Skip to content

Commit

Permalink
Fix of TestWorkQueueHealthCheck test
Browse files Browse the repository at this point in the history
Add check that workers actually started before we run main test logic.
If there are no workers live check returns true because 0 workers is
running. And then no error is generated cause workers has not started
(Healthy() return true even if no workers).
  • Loading branch information
aLekSer authored and jkowalski committed Feb 7, 2019
1 parent 7b6cf3b commit 6f30bdb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/util/workerqueue/workerqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ func TestWorkQueueHealthCheck(t *testing.T) {
server := httptest.NewServer(health)
defer server.Close()

const workersCount = 1
stop := make(chan struct{})
go wq.Run(1, stop)
go wq.Run(workersCount, stop)

url := server.URL + "/live"
// Wait for worker to actually start
err := wait.PollImmediate(100*time.Millisecond, 5*time.Second, func() (bool, error) {
rc := wq.RunCount()
logrus.WithField("runcount", rc).Info("Checking run count before liveness check")
return rc == workersCount, nil
})
assert.Nil(t, err)

f := func(t *testing.T, url string, status int) {

// sometimes the http server takes a bit to start up
err := wait.PollImmediate(time.Second, 5*time.Second, func() (bool, error) {
resp, err := http.Get(url)
Expand All @@ -142,11 +148,12 @@ func TestWorkQueueHealthCheck(t *testing.T) {
assert.Nil(t, err)
}

url := server.URL + "/live"
f(t, url, http.StatusOK)

close(stop)
// closing can take a short while
err := wait.PollImmediate(time.Second, 5*time.Second, func() (bool, error) {
err = wait.PollImmediate(time.Second, 5*time.Second, func() (bool, error) {
rc := wq.RunCount()
logrus.WithField("runcount", rc).Info("Checking run count")
return rc == 0, nil
Expand Down

0 comments on commit 6f30bdb

Please sign in to comment.