Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TT-1188 mdcb testing framework / Gw refactor #3438

Merged
merged 131 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
ae21e70
created struct to handle slaved cluster
sredxny Dec 23, 2020
9021300
fix number of params sent
sredxny Dec 23, 2020
c8fd930
added function to get an api for integration testing
sredxny Jan 5, 2021
1e69d88
added function to return policy by id to be used in integration tests
sredxny Jan 5, 2021
1f5b906
fix return values
sredxny Jan 5, 2021
b0fd8f8
refactor
sredxny Jan 7, 2021
95bec09
gofmt file
sredxny Jan 7, 2021
92bfc7b
added port attribute for gw
sredxny Jan 7, 2021
a29f8b6
rewrite how to get s.Url based on gateway for testing
sredxny Jan 7, 2021
67bf702
created rpc connection pool
sredxny Jan 8, 2021
bd06a90
removed deug logs in rpc
sredxny Jan 11, 2021
4868283
remove commented unused code
sredxny Jan 11, 2021
5625304
remove commented unused code
sredxny Jan 11, 2021
3159e2e
change gw receiver to use pointer
sredxny Jan 25, 2021
2b33efc
started to wrap configs inside gw
sredxny Jan 28, 2021
c3c5996
move all to depend to gw
sredxny Feb 4, 2021
fab2b45
gw is now an attribute rather than embeded in structs
sredxny Feb 4, 2021
f0d92ad
set gw attr to rpcStorageHandler
sredxny Feb 4, 2021
c97b921
moved GlobalEventsJSVM from global to gw attr
sredxny Feb 4, 2021
f1d0938
moved analytics from global into gateway struct
sredxny Feb 5, 2021
b4b1733
moved MainNotifier inside Gw struct
sredxny Feb 5, 2021
289db27
moved DefaultOrgStore into gw struct
sredxny Feb 5, 2021
d0ce2d3
moved DefaultQuotaStore into Gw struct
sredxny Feb 5, 2021
f79e6f0
moved GlobalSessionManager into gw struct
sredxny Feb 5, 2021
399773a
oved MonitoringHandler into gw struct
sredxny Feb 5, 2021
f077715
moved RPCListener from global to gw struct
sredxny Feb 5, 2021
d992c5a
moved DashService from global to gw struct
sredxny Feb 5, 2021
93cabd3
moved CertificateManager from global to gw struct
sredxny Feb 5, 2021
291ca9b
moved apis map,specs, byId and mutex from global to gw struct
sredxny Feb 5, 2021
9587871
moved dnsCacheManager from global to gw struct
sredxny Feb 5, 2021
06b9eb5
move consulKVStore and vaultKVStore from global to gw struct
sredxny Feb 5, 2021
12c6086
moved keyGen from global to gw struct
sredxny Feb 5, 2021
2a237ae
moved LE_MANAGER and LE_FIRSTRUN from global into gw struct
sredxny Feb 5, 2021
8ca1d31
moved runningTestsMu and testMode from global to gw struct
sredxny Feb 5, 2021
d943641
moved policies from global to gw struct
sredxny Feb 5, 2021
6489783
fix tests with new refactor
sredxny Feb 16, 2021
d84cdef
fixing tests, gofmt files
sredxny Feb 17, 2021
420785c
updated with master
sredxny Feb 17, 2021
b9f28b2
remove debug comments
sredxny Feb 17, 2021
1254c1d
fix test where proxy cannot be initialized, and template/url is parse…
sredxny Feb 18, 2021
58617fa
fix export of TykTriggerEvent
sredxny Feb 18, 2021
b5e97cb
update with master
sredxny Feb 18, 2021
f2ed190
update with master
sredxny Feb 18, 2021
c3c4dca
updated with master
sredxny Feb 18, 2021
e74b00e
fix tests of middlewares
sredxny Feb 19, 2021
b96b4a6
init keygenerator
sredxny Feb 19, 2021
3563b18
updated with master
sredxny Feb 19, 2021
16ae852
updated with master
sredxny Feb 24, 2021
7509907
fix TestCORS
sredxny Feb 24, 2021
aee6798
fix test TestGroupResetHandler
sredxny Feb 25, 2021
d79c4b0
gofmt files
sredxny Feb 25, 2021
5449dbd
removed unused const defReadTimeout and defWritteTimeout
sredxny Feb 25, 2021
026a6d8
removed unused const defReadTimeout and defWritteTimeout
sredxny Feb 25, 2021
15c11d1
fixing lint
sredxny Feb 25, 2021
43d1386
fixing lint
sredxny Feb 25, 2021
3adcf28
Merge branch 'master' into TT-1188-mdcb-testing-framework
sredxny Feb 25, 2021
c3529aa
fix where we remove the app path
sredxny Feb 26, 2021
9556e5c
fix TestGatewayTLS and TestAPIMutualTLS
sredxny Feb 26, 2021
bb279ee
fix TestGatewayControlAPIMutualTLS
sredxny Feb 26, 2021
0b07d64
fix TestCipherSuites
sredxny Feb 26, 2021
375bb15
fix TestAPICertificate
sredxny Feb 26, 2021
1f37a6d
started to fix TestKeyWithCertificateTLS
sredxny Feb 27, 2021
988669b
debugging
sredxny Feb 27, 2021
f029423
finish fix cert tests
sredxny Feb 27, 2021
d09c3c7
finish fix cert tests
sredxny Feb 27, 2021
2a72dc8
fix TestHoostChecker
sredxny Feb 27, 2021
2a1187c
fix TestInitGenericEventHandlers
sredxny Feb 27, 2021
fd21db2
fix TestVirtualEndpoint TestVirtualEndpoint500 TestVirtualEndpointSe…
sredxny Feb 27, 2021
1f172d0
fix TestTykMakeHTTPRequest
sredxny Feb 27, 2021
ed318bd
fix TestHTTP2_TLS
sredxny Feb 27, 2021
3082604
fix TestGRPC_TLS
sredxny Feb 27, 2021
4555029
fix TestGRPC_MutualTLS
sredxny Feb 27, 2021
ecfdaa7
fix TestGRPC_BasicAuthentication
sredxny Feb 27, 2021
8fb40a4
fix TestGRPC_TokenBasedAuthentication
sredxny Feb 27, 2021
b67cad3
fix TestGRPC_Stream_MutualTLS
sredxny Feb 27, 2021
98c5d3a
fix TestGRPC_Stream_TokenBasedAuthentication
sredxny Feb 27, 2021
20abb49
fix ts := StartTest(nil)
sredxny Feb 27, 2021
b412c07
fix TestProcessRequestOffThreadQuotaLimit
sredxny Feb 28, 2021
8fe6b89
fix ts := StartTest(nil)
sredxny Feb 28, 2021
929f052
fix TestContextVarsMiddleware
sredxny Feb 28, 2021
7920c3a
fix TestJWTSessionHMAC
sredxny Feb 28, 2021
4c64669
fix TestMultiSession_BA_Standard_OK
sredxny Feb 28, 2021
c7c7207
fix TestBasicAuth
sredxny Feb 28, 2021
d2d630e
fix TestValueExtractor
sredxny Feb 28, 2021
9a0dcb7
fix TestTransformXMLCrash
sredxny Feb 28, 2021
776ea1e
fix TestTransform
sredxny Feb 28, 2021
87ca270
fix TestHMACAuthSessionPass
sredxny Feb 28, 2021
cd18dc4
fix TestVersioning
sredxny Feb 28, 2021
faa55c2
fix oauth and some webhooks tests
sredxny Feb 28, 2021
5e367ce
fix TestHashKeyHandler
sredxny Feb 28, 2021
3dbf0dd
fix TestNewValid and TestNewInvalid
sredxny Feb 28, 2021
d01390d
fix TestNewCustomTemplate
sredxny Feb 28, 2021
3a61a9b
fix TestWebhookContentTypeHeader
sredxny Feb 28, 2021
ce17fc5
gofmt gateway file
sredxny Feb 28, 2021
76d4f4f
Merge branch 'master' into TT-1188-mdcb-testing-framework
sredxny Feb 28, 2021
56946ef
recover files removed accidentally
sredxny Feb 28, 2021
b103f28
goimports files
sredxny Feb 28, 2021
5aea3f8
cleaning
sredxny Feb 28, 2021
1e6a8b2
cleaning
sredxny Feb 28, 2021
95fd2eb
updated TestSyncAPISpecsRPCFailure_CheckGlobals
sredxny Feb 28, 2021
fc7e7a7
fixing TestSyncAPISpecsRPCSuccess
sredxny Feb 28, 2021
45b4293
fix TestSyncAPISpecsRPCSuccess
sredxny Feb 28, 2021
5c6e3ba
more httppofiler test
sredxny Feb 28, 2021
6540a6a
clean comments
sredxny Feb 28, 2021
bb02967
remove bin
sredxny Mar 1, 2021
2801fa2
fix ReloadMachinery tests
sredxny Mar 1, 2021
2d2a7b2
update test documenttion
sredxny Mar 2, 2021
06bf3a1
slight changes in TestCoProcessDispatchEvent
sredxny Mar 2, 2021
a233324
bundle functions moved into gw
sredxny Mar 2, 2021
2dc311d
moved drlOnce into GW
sredxny Mar 2, 2021
bc89a55
moved RpcPurgeOnce into gw
sredxny Mar 2, 2021
32dcd11
fix hostchecker tests
sredxny Mar 3, 2021
c09c123
fix conficlts
sredxny Mar 3, 2021
3ffbcee
exposed some gw methods so we enable them to be consumed from dashboard
sredxny Mar 3, 2021
6b39e22
start RPC listener for gw test
sredxny Mar 4, 2021
f32bd09
modify how to handle the reloadLoops on tests. It should be the same …
sredxny Mar 4, 2021
f73b685
restore deleted files
sredxny Mar 4, 2021
156480f
restore deleted files
sredxny Mar 4, 2021
c673f88
removed binary
sredxny Mar 4, 2021
a0b123e
fixing tests
sredxny Mar 16, 2021
3047fc8
estabilization of tests
sredxny Mar 17, 2021
8195b3a
a way more stable tests
sredxny Mar 17, 2021
92187a7
updated with master
sredxny Mar 17, 2021
57322ec
Merge branch 'master' into TT-1188-mdcb-testing-framework
sredxny Mar 17, 2021
b4d2471
improve wording in documentation
sredxny Mar 22, 2021
b597607
Merge branch 'TT-1188-mdcb-testing-framework' of github.com:TykTechno…
sredxny Mar 22, 2021
92c7446
update with master
sredxny Mar 23, 2021
5d95a5a
Merge branch 'master' into TT-1188-mdcb-testing-framework
sredxny Mar 24, 2021
40ce5d7
uncomment tests
sredxny Mar 24, 2021
62771b0
gofmt gateway_test.go
sredxny Mar 24, 2021
1396308
fix conflicts with mster
sredxny Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
sredxny committed Jan 7, 2021
commit b0fd8f8891dfec084460ceaa640cc39eae831e70
8 changes: 6 additions & 2 deletions gateway/api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,15 @@ func (a APIDefinitionLoader) FromDashboardService(endpoint, secret string) ([]*A
}

// FromCloud will connect and download ApiDefintions from a Mongo DB instance.
func (a APIDefinitionLoader) FromRPC(orgId string) ([]*APISpec, error) {
func (a APIDefinitionLoader) FromRPC(orgId string, gw Gateway) ([]*APISpec, error) {
if rpc.IsEmergencyMode() {
return LoadDefinitionsFromRPCBackup()
}
store := RPCStorageHandler{}

store := RPCStorageHandler{
DoReload:gw.DoReload,
}

if !store.Connect() {
return nil, errors.New("Can't connect RPC layer")
}
Expand Down
10 changes: 5 additions & 5 deletions gateway/api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,14 @@ func sanitizeProxyPaths(apiSpec *APISpec, request *http.Request) {
request.URL.RawPath = apiSpec.StripListenPath(request, request.URL.RawPath)
}

func loadGlobalApps() {
func(gw Gateway) loadGlobalApps() {
// we need to make a full copy of the slice, as loadApps will
// use in-place to sort the apis.
apisMu.RLock()
specs := make([]*APISpec, len(apiSpecs))
copy(specs, apiSpecs)
apisMu.RUnlock()
loadApps(specs)
gw.loadApps(specs)
}

func trimCategories(name string) string {
Expand Down Expand Up @@ -736,7 +736,7 @@ func loadGraphQLPlayground(spec *APISpec, router *mux.Router) {
}

// Create the individual API (app) specs based on live configurations and assign middleware
func loadApps(specs []*APISpec) {
func(gw Gateway) loadApps(specs []*APISpec) {
mainLog.Info("Loading API configurations.")

tmpSpecRegister := make(map[string]*APISpec)
Expand All @@ -761,7 +761,7 @@ func loadApps(specs []*APISpec) {
muxer := &proxyMux{}
router := mux.NewRouter()
router.NotFoundHandler = http.HandlerFunc(muxer.handle404)
loadControlAPIEndpoints(router)
gw.loadControlAPIEndpoints(router)

muxer.setRouter(port, "", router)

Expand Down Expand Up @@ -807,7 +807,7 @@ func loadApps(specs []*APISpec) {
}()
}

defaultProxyMux.swap(muxer)
gw.DefaultProxyMux.swap(muxer)

// Swap in the new register
apisMu.Lock()
Expand Down
3 changes: 2 additions & 1 deletion gateway/proxy_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ type proxyMux struct {
again again.Again
}

/*
var defaultProxyMux = &proxyMux{
again: again.New(),
}
}*/

func (m *proxyMux) getProxy(listenPort int) *proxy {
if listenPort == 0 {
Expand Down
3 changes: 2 additions & 1 deletion gateway/rpc_storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type RPCStorageHandler struct {
KeyPrefix string
HashKeys bool
SuppressRegister bool
DoReload func()
}

var RPCGlobalCache = cache.New(30*time.Second, 15*time.Second)
Expand Down Expand Up @@ -125,7 +126,7 @@ func (r *RPCStorageHandler) Connect() bool {
func() {
reloadURLStructure(nil)
},
DoReload,
r.DoReload,
)
}

Expand Down
55 changes: 35 additions & 20 deletions gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func buildConnStr(resource string) string {
return config.Global().DBAppConfOptions.ConnectionString + resource
}

func syncAPISpecs() (int, error) {
func(gw Gateway) syncAPISpecs() (int, error) {
loader := APIDefinitionLoader{}
apisMu.Lock()
defer apisMu.Unlock()
Expand All @@ -290,7 +290,7 @@ func syncAPISpecs() (int, error) {
mainLog.Debug("Using RPC Configuration")

var err error
s, err = loader.FromRPC(config.Global().SlaveOptions.RPCKey)
s, err = loader.FromRPC(config.Global().SlaveOptions.RPCKey, gw)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -396,15 +396,15 @@ func controlAPICheckClientCertificate(certLevel string, next http.Handler) http.
}

// loadControlAPIEndpoints loads the endpoints used for controlling the Gateway.
func loadControlAPIEndpoints(muxer *mux.Router) {
func(gw Gateway) loadControlAPIEndpoints(muxer *mux.Router) {
hostname := config.Global().HostName
if config.Global().ControlAPIHostname != "" {
hostname = config.Global().ControlAPIHostname
}

if muxer == nil {
cp := config.Global().ControlAPIPort
muxer = defaultProxyMux.router(cp, "")
muxer = gw.DefaultProxyMux.router(cp, "")
if muxer == nil {
if cp != 0 {
log.Error("Can't find control API router")
Expand Down Expand Up @@ -700,7 +700,7 @@ func rpcReloadLoop(rpcKey string) {

var reloadMu sync.Mutex

func DoReload() {
func(gw Gateway) DoReload() {
reloadMu.Lock()
defer reloadMu.Unlock()

Expand All @@ -716,7 +716,7 @@ func DoReload() {
}

// load the specs
if count, err := syncAPISpecs(); err != nil {
if count, err := gw.syncAPISpecs(); err != nil {
mainLog.Error("Error during syncing apis:", err.Error())
return
} else {
Expand All @@ -727,7 +727,7 @@ func DoReload() {
return
}
}
loadGlobalApps()
gw.loadGlobalApps()

mainLog.Info("API reload complete")
}
Expand All @@ -745,7 +745,7 @@ func shouldReload() ([]func(), bool) {
return n, true
}

func reloadLoop(ctx context.Context, tick <-chan time.Time, complete ...func()) {
func(gw Gateway) reloadLoop(ctx context.Context, tick <-chan time.Time, complete ...func()) {
for {
select {
case <-ctx.Done():
Expand All @@ -760,7 +760,7 @@ func reloadLoop(ctx context.Context, tick <-chan time.Time, complete ...func())
}
start := time.Now()
mainLog.Info("reload: initiating")
DoReload()
gw.DoReload()
mainLog.Info("reload: complete")
mainLog.Info("Initiating coprocess reload")
DoCoprocessReload()
Expand Down Expand Up @@ -1196,6 +1196,14 @@ func getGlobalStorageHandler(keyPrefix string, hashKeys bool) storage.Handler {
return &storage.RedisCluster{KeyPrefix: keyPrefix, HashKeys: hashKeys}
}

func NewGateway()Gateway{
return Gateway{
DefaultProxyMux:&proxyMux{
again: again.New(),
},
}
}

func Start() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -1206,6 +1214,8 @@ func Start() {
os.Exit(0)
}

gw := NewGateway()

SetNodeID("solo-" + uuid.NewV4().String())

if err := initialiseSystem(ctx); err != nil {
Expand Down Expand Up @@ -1237,7 +1247,7 @@ func Start() {
os.Setenv("TYK_SERVICE_NODEID", GetNodeID())
}
}
err := again.ListenFrom(&defaultProxyMux.again, onFork)
err := again.ListenFrom(&gw.DefaultProxyMux.again, onFork)
if err != nil {
mainLog.Errorf("Initializing again %s", err)
}
Expand All @@ -1246,7 +1256,7 @@ func Start() {
trace.SetLogger(mainLog)
defer trace.Close()
}
start(ctx)
gw.start(ctx)
go storage.ConnectToRedis(ctx, func() {
reloadURLStructure(func() {})
})
Expand Down Expand Up @@ -1279,17 +1289,17 @@ func Start() {

// TODO: replace goagain with something that support multiple listeners
// Example: https://gravitational.com/blog/golang-ssh-bastion-graceful-restarts/
startServer()
gw.startServer()

if again.Child() {
// This is a child process, we need to murder the parent now
if err := again.Kill(); err != nil {
mainLog.Fatal(err)
}
}
again.Wait(&defaultProxyMux.again)
again.Wait(&gw.DefaultProxyMux.again)
mainLog.Info("Stop signal received.")
if err := defaultProxyMux.again.Close(); err != nil {
if err := gw.DefaultProxyMux.again.Close(); err != nil {
mainLog.Error("Closing listeners: ", err)
}
// stop analytics workers
Expand Down Expand Up @@ -1335,7 +1345,7 @@ func writeProfiles() {
}
}

func start(ctx context.Context) {
func (gw Gateway) start(ctx context.Context) {
// Set up a default org manager so we can traverse non-live paths
if !config.Global().SupressDefaultOrgStore {
mainLog.Debug("Initialising default org store")
Expand Down Expand Up @@ -1364,7 +1374,7 @@ func start(ctx context.Context) {

// 1s is the minimum amount of time between hot reloads. The
// interval counts from the start of one reload to the next.
go reloadLoop(ctx, time.Tick(time.Second))
go gw.reloadLoop(ctx, time.Tick(time.Second))
go reloadQueueLoop(ctx)
}

Expand Down Expand Up @@ -1428,19 +1438,24 @@ func setupPortsWhitelist() {
config.SetGlobal(globalConf)
}

func startServer() {
type Gateway struct {
DefaultProxyMux *proxyMux
}

func (gw Gateway) startServer() {
// Ensure that Control listener and default http listener running on first start
muxer := &proxyMux{}

router := mux.NewRouter()
loadControlAPIEndpoints(router)
gw.loadControlAPIEndpoints(router)
muxer.setRouter(config.Global().ControlAPIPort, "", router)

if muxer.router(config.Global().ListenPort, "") == nil {
muxer.setRouter(config.Global().ListenPort, "", mux.NewRouter())
}

defaultProxyMux.swap(muxer)
// defaultProxyMux.swap(muxer)
gw.DefaultProxyMux.swap(muxer)

// handle dashboard registration and nonces if available
handleDashboardRegistration()
Expand All @@ -1457,6 +1472,6 @@ func startServer() {
mainLog.Info("--> Listening on port: ", config.Global().ListenPort)
mainLog.Info("--> PID: ", hostDetails.PID)
if !rpc.IsEmergencyMode() {
DoReload()
gw.DoReload()
}
}
23 changes: 13 additions & 10 deletions gateway/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type ReloadMachinery struct {
stop chan struct{}
}

var globalGateway Gateway

func NewReloadMachinery() *ReloadMachinery {
return &ReloadMachinery{
reloadTick: make(chan time.Time),
Expand Down Expand Up @@ -218,6 +220,7 @@ func (r *ReloadMachinery) TickOk(t *testing.T) {

func InitTestMain(ctx context.Context, m *testing.M, genConf ...func(globalConf *config.Config)) int {
setTestMode(true)
globalGateway = NewGateway()
testServerRouter = testHttpHandler()
testServer := &http.Server{
Addr: testHttpListen,
Expand Down Expand Up @@ -288,7 +291,7 @@ func InitTestMain(ctx context.Context, m *testing.M, genConf ...func(globalConf
cli.Init(VERSION, confPaths)
initialiseSystem(ctx)
// Small part of start()
loadControlAPIEndpoints(mainRouter())
globalGateway.loadControlAPIEndpoints(mainRouter())
if analytics.GeoIPDB == nil {
panic("GeoIPDB was not initialized")
}
Expand All @@ -305,7 +308,7 @@ func InitTestMain(ctx context.Context, m *testing.M, genConf ...func(globalConf
time.Sleep(10 * time.Millisecond)
}
go startPubSubLoop()
go reloadLoop(ctx, ReloadTestCase.ReloadTicker(), ReloadTestCase.OnReload)
go globalGateway.reloadLoop(ctx, ReloadTestCase.ReloadTicker(), ReloadTestCase.OnReload)
go reloadQueueLoop(ctx, ReloadTestCase.OnQueued)
go reloadSimulation()
exitCode := m.Run()
Expand Down Expand Up @@ -395,15 +398,15 @@ func bundleHandleFunc(w http.ResponseWriter, r *http.Request) {
z.Close()
}
func mainRouter() *mux.Router {
return getMainRouter(defaultProxyMux)
return getMainRouter(globalGateway.DefaultProxyMux)
}

func mainProxy() *proxy {
return defaultProxyMux.getProxy(config.Global().ListenPort)
return globalGateway.DefaultProxyMux.getProxy(config.Global().ListenPort)
}

func controlProxy() *proxy {
p := defaultProxyMux.getProxy(config.Global().ControlAPIPort)
p := globalGateway.DefaultProxyMux.getProxy(config.Global().ControlAPIPort)
if p != nil {
return p
}
Expand Down Expand Up @@ -818,7 +821,7 @@ func CreateDefinitionFromString(defStr string) *APISpec {

func LoadSampleAPI(def string) (spec *APISpec) {
spec = CreateDefinitionFromString(def)
loadApps([]*APISpec{spec})
globalGateway.loadApps([]*APISpec{spec})
return
}

Expand Down Expand Up @@ -859,7 +862,7 @@ func (s *Test) Start(slavedClusterConfig *SlaveDataCenter) {
l.Close()
globalConf := config.Global()
globalConf.ListenPort, _ = strconv.Atoi(port)

gw := NewGateway()
if s.config.sepatateControlAPI {
l, _ := net.Listen("tcp", "127.0.0.1:0")

Expand All @@ -884,7 +887,7 @@ func (s *Test) Start(slavedClusterConfig *SlaveDataCenter) {

setupPortsWhitelist()

startServer()
gw.startServer()
ctx, cancel := context.WithCancel(context.Background())
s.cacnel = cancel
setupGlobals(ctx)
Expand Down Expand Up @@ -937,7 +940,7 @@ func (s *Test) Close() {
if s.cacnel != nil {
s.cacnel()
}
defaultProxyMux.swap(&proxyMux{})
globalGateway.DefaultProxyMux.swap(&proxyMux{})
if s.config.sepatateControlAPI {
globalConf := config.Global()
globalConf.ControlAPIPort = 0
Expand Down Expand Up @@ -1230,7 +1233,7 @@ func LoadAPI(specs ...*APISpec) (out []*APISpec) {
}
}

DoReload()
globalGateway.DoReload()

for _, spec := range specs {
out = append(out, getApiSpec(spec.APIID))
Expand Down