From 6f30bdb88585e62f7c3879c53a0b58af1666f8fd Mon Sep 17 00:00:00 2001 From: Alexander Apalikov Date: Thu, 7 Feb 2019 16:04:38 +0300 Subject: [PATCH] Fix of TestWorkQueueHealthCheck test 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). --- pkg/util/workerqueue/workerqueue_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/util/workerqueue/workerqueue_test.go b/pkg/util/workerqueue/workerqueue_test.go index 01e6657d1e..e55bdea8f7 100644 --- a/pkg/util/workerqueue/workerqueue_test.go +++ b/pkg/util/workerqueue/workerqueue_test.go @@ -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) @@ -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