Skip to content

Commit

Permalink
Fix deactivating API if it is the only one (TykTechnologies#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded authored and buger committed Nov 30, 2017
1 parent 46eafb2 commit ef1934a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ petstore.json
*.prof
*.pdf
*.mmdb
*.cov
!testdata/*.mmdb
*.pid
coprocess_gen_test.go
Expand Down
6 changes: 6 additions & 0 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,12 @@ func testHttp(t *testing.T, tests []tykHttpTest, separateControlPort bool) {
panic(err)
}

// reset globals to initial state before running every set of tests
apisMu.Lock()
apiSpecs = []*APISpec{}
apisByID = map[string]*APISpec{}
apisMu.Unlock()

setupGlobals()
// This is emulate calling start()
// But this lines is the only thing needed for this tests
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func getApiSpec(apiID string) *APISpec {
return spec
}

func apisByIDLen() int {
apisMu.RLock()
defer apisMu.RUnlock()
return len(apisByID)
}

// Create all globals and init connection handlers
func setupGlobals() {
mainRouter = mux.NewRouter()
Expand Down Expand Up @@ -618,7 +624,9 @@ func doReload() {
syncPolicies()
// load the specs
count := syncAPISpecs()
if count == 0 {
// skip re-loading only if dashboard service reported 0 APIs
// and current registry had 0 APIs
if count == 0 && apisByIDLen() == 0 {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Warning("No API Definitions found, not reloading")
Expand Down

0 comments on commit ef1934a

Please sign in to comment.