Skip to content

Commit

Permalink
Fix race over 'defaultTestConfig'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tit Petric committed Oct 28, 2024
1 parent 33107b6 commit aa5bb05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
13 changes: 6 additions & 7 deletions gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,16 +840,13 @@ func TestMultiTargetProxy(t *testing.T) {
}

func TestCustomDomain(t *testing.T) {
ts := StartTest(nil)
t.Cleanup(ts.Close)

localClient := test.NewClientLocal()

t.Run("With custom domain support", func(t *testing.T) {
globalConf := ts.Gw.GetConfig()
globalConf.EnableCustomDomains = true
ts.Gw.SetConfig(globalConf)
defer ts.ResetTestConfig()
ts := StartTest(func(conf *config.Config) {
globalConf.EnableCustomDomains = true
})
t.Cleanup(ts.Close)

ts.Gw.BuildAndLoadAPI(
func(spec *APISpec) {
Expand All @@ -871,6 +868,8 @@ func TestCustomDomain(t *testing.T) {
})

t.Run("Without custom domain support", func(t *testing.T) {
ts := StartTest(nil)
t.Cleanup(ts.Close)

ts.Gw.BuildAndLoadAPI(
func(spec *APISpec) {
Expand Down
8 changes: 0 additions & 8 deletions gateway/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ var (
// Used to store the test bundles:
testMiddlewarePath, _ = ioutil.TempDir("", "tyk-middleware-path")

defaultTestConfig config.Config
EnableTestDNSMock = false
MockHandle *test.DnsMockHandle
)
Expand Down Expand Up @@ -261,11 +260,6 @@ func InitTestMain(ctx context.Context, m *testing.M) int {
// TestBrokenClients
// TestGRPC_TokenBasedAuthentication

// ResetTestConfig resets the config for the global gateway
func (s *Test) ResetTestConfig() {
s.Gw.SetConfig(defaultTestConfig)
}

// simulate reloads in the background, i.e. writes to
// global variables that should not be accessed in a
// racy way like the policies and api specs maps.
Expand Down Expand Up @@ -1183,7 +1177,6 @@ func (s *Test) newGateway(genConf func(globalConf *config.Config)) *Gateway {
gw.CoProcessInit()
gw.afterConfSetup()

defaultTestConfig = gwConfig
gw.SetConfig(gwConfig)

cli.Init(confPaths)
Expand Down Expand Up @@ -1895,7 +1888,6 @@ func (p *httpProxyHandler) handleHTTP(w http.ResponseWriter, req *http.Request)
}

func (p *httpProxyHandler) Stop(s *Test) error {
s.ResetTestConfig()
return p.server.Close()
}

Expand Down

0 comments on commit aa5bb05

Please sign in to comment.