Make Time Limit confiugrable and in seconds. Added a Neg TC, but it still does not work.
diff --git a/apigee_sync.go b/apigee_sync.go index e02a790..829fc86 100644 --- a/apigee_sync.go +++ b/apigee_sync.go
@@ -64,7 +64,7 @@ times = pollInterval } log.Debugf("Connecting to changeserver...") - time.Sleep(time.Duration(times) * 100 * time.Millisecond) + time.Sleep(time.Duration(times) * time.Second) } else { // Reset sleep interval times = 1 @@ -168,18 +168,17 @@ * The plugins should have finished what they are doing. * Wait till they are done. * If they take longer than expected - abort apid(?) - * (Should there be a configurable Fudge factor?) FIXME */ - for count := 0; count < 1000; count++ { + for count := 0; count < config.GetInt(configTimeLimit); count++ { if chfin == false { log.Info("Waiting for plugins to complete...") - time.Sleep(time.Duration(count) * 100 * time.Millisecond) + time.Sleep(time.Duration(count) * time.Second) } else { break } } if chfin == false { - log.Fatal("Never got ack from plugins. Investigate..") + log.Panicf("Never got ack from plugins. Investigate..") } } else { log.Info("No Changes detected for Scopes ", scopes) @@ -300,15 +299,14 @@ /* Phase 1 */ DownloadSnapshot() - /* * Give some time for all the plugins to process the Downloaded * Snapshot */ - for count := 0; count < 60; count++ { + for count := 0; count < config.GetInt(configTimeLimit); count++ { if !downloadBootSnapshot { log.Debug("Waiting for bootscope snapshot download...") - time.Sleep(time.Duration(count) * 100 * time.Millisecond) + time.Sleep(time.Duration(count) * time.Second) } else { break }
diff --git a/apigee_sync_test.go b/apigee_sync_test.go index f853c93..ce1f22f 100644 --- a/apigee_sync_test.go +++ b/apigee_sync_test.go
@@ -192,7 +192,7 @@ config.Set(configScopeId, scope) config.Set(configConsumerKey, key) config.Set(configConsumerSecret, secret) - + config.Set(configTimeLimit, 60) // set up temporary test database tmpDir, err := ioutil.TempDir("", "apigee_sync_test") Expect(err).NotTo(HaveOccurred()) @@ -230,7 +230,7 @@ // There should be 2 scopes now _, ok := event.(*common.ChangeList) if ok { - time.Sleep(200 * time.Millisecond) + time.Sleep(1 * time.Second) db, err := data.DB() Expect(err).NotTo(HaveOccurred()) err = db.QueryRow("Select count(scp.id) from apid_config_scope as scp INNER JOIN apid_config as ap WHERE scp.apid_config_id = ap.id").Scan(&scount) @@ -255,7 +255,37 @@ apid.Events().Listen(ApigeeSyncEventSelector, h1) events.ListenFunc(apid.EventDeliveredSelector, donehandler) - }) + }, 10) + + It("Plugin does not respond in time", func(done Done) { + defer func() { + if r := recover(); r != nil { + var ok bool + _, ok = r.(error) + if !ok { + Expect(r).Should(Equal("Never got ack from plugins. Investigate..")) + } else { + Fail("Unexpected panic handling error") + } + } + + }() + h2 := &test_handler{ + "sync data", + func(event apid.Event) { + _, ok := event.(*common.ChangeList) + if ok { + // Sleep more than tolerated + time.Sleep(5 * time.Second) + close(done) + } else { + Fail("Unexpected event") + } + }, + } + config.Set(configTimeLimit, 2) + apid.Events().Listen(ApigeeSyncEventSelector, h2) + }, 10) })
diff --git a/init.go b/init.go index 65b72ad..14d32a6 100644 --- a/init.go +++ b/init.go
@@ -14,7 +14,7 @@ configConsumerSecret = "apigeesync_consumer_secret" configScopeId = "apigeesync_bootstrap_id" configSnapshotProtocol = "apigeesync_snapshot_proto" - configUnitTestMode = "apigeesync_UnitTest_mode" + configTimeLimit = "apigeesync_timelimit_in_secs" ApigeeSyncEventSelector = "ApigeeSync" ) @@ -62,6 +62,7 @@ events.ListenFunc(apid.SystemEventsSelector, postInitPlugins) config.SetDefault(configPollInterval, 120) + config.SetDefault(configTimeLimit, 60) gapidConfigId = config.GetString(configScopeId) db, err := data.DB() if err != nil {