Skip to content

Commit

Permalink
Revert "Merging to release-5.2: [TT-10518] Tests/address some racy te…
Browse files Browse the repository at this point in the history
…sts (#5771)"

This reverts commit 85ca35d.
  • Loading branch information
sredxny committed Mar 3, 2024
1 parent 1957efc commit 36a77d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 44 deletions.
8 changes: 2 additions & 6 deletions gateway/looping_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !race || unstable
// +build !race unstable
//go:build !race
// +build !race

// Looping by itself has race nature
package gateway
Expand Down Expand Up @@ -185,8 +185,6 @@ func TestLooping(t *testing.T) {
})

t.Run("VirtualEndpoint or plugins", func(t *testing.T) {
test.Flaky(t) // TT-10511

ts.testPrepareVirtualEndpoint(`
function testVirtData(request, session, config) {
var loopLocation = "/default"
Expand Down Expand Up @@ -328,8 +326,6 @@ func TestLooping(t *testing.T) {
}

func TestConcurrencyReloads(t *testing.T) {
test.Racy(t) // TT-10510

var wg sync.WaitGroup

ts := StartTest(nil)
Expand Down
42 changes: 8 additions & 34 deletions gateway/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io/ioutil"
"net/http"
"strconv"
"sync"
"time"

"github.com/TykTechnologies/tyk/internal/cache"
Expand Down Expand Up @@ -233,30 +232,15 @@ func (gw *Gateway) mwList(mws ...TykMiddleware) []alice.Constructor {
// BaseMiddleware wraps up the ApiSpec and Proxy objects to be included in a
// middleware handler, this can probably be handled better.
type BaseMiddleware struct {
Spec *APISpec
Proxy ReturningHttpHandler
Gw *Gateway `json:"-"`

loggerMu sync.Mutex
logger *logrus.Entry
}

func (t *BaseMiddleware) Base() *BaseMiddleware {
t.loggerMu.Lock()
defer t.loggerMu.Unlock()

return &BaseMiddleware{
Spec: t.Spec,
Proxy: t.Proxy,
Gw: t.Gw,
logger: t.logger,
}
Spec *APISpec
Proxy ReturningHttpHandler
logger *logrus.Entry
Gw *Gateway `json:"-"`
}

func (t *BaseMiddleware) Logger() (logger *logrus.Entry) {
t.loggerMu.Lock()
defer t.loggerMu.Unlock()
func (t BaseMiddleware) Base() *BaseMiddleware { return &t }

func (t BaseMiddleware) Logger() (logger *logrus.Entry) {
if t.logger == nil {
t.logger = logrus.NewEntry(log)
}
Expand All @@ -265,21 +249,11 @@ func (t *BaseMiddleware) Logger() (logger *logrus.Entry) {
}

func (t *BaseMiddleware) SetName(name string) {
logger := t.Logger()

t.loggerMu.Lock()
defer t.loggerMu.Unlock()

t.logger = logger.WithField("mw", name)
t.logger = t.Logger().WithField("mw", name)
}

func (t *BaseMiddleware) SetRequestLogger(r *http.Request) {
logger := t.Logger()

t.loggerMu.Lock()
defer t.loggerMu.Unlock()

t.logger = t.Gw.getLogEntryForRequest(logger, r, ctxGetAuthToken(r), nil)
t.logger = t.Gw.getLogEntryForRequest(t.Logger(), r, ctxGetAuthToken(r), nil)
}

func (t BaseMiddleware) Init() {}
Expand Down
4 changes: 2 additions & 2 deletions gateway/mw_organisation_activity_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !race || unstable
// +build !race unstable
//go:build !race
// +build !race

package gateway

Expand Down
4 changes: 2 additions & 2 deletions gateway/rpc_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !race || unstable
// +build !race unstable
//go:build !race
// +build !race

package gateway

Expand Down

0 comments on commit 36a77d2

Please sign in to comment.