From 3d6c65f53b1ec77c5f48b2a590d7ee84d5210b40 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Tue, 31 Mar 2020 00:09:20 +0800 Subject: [PATCH] fix[UT]:improve the UT cases of enqueuer (#11358) - change the test cron spec - use cretaed timer for timeout Signed-off-by: Steven Zou --- src/jobservice/period/enqueuer_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/jobservice/period/enqueuer_test.go b/src/jobservice/period/enqueuer_test.go index 8b38bde22..d2f0d3751 100644 --- a/src/jobservice/period/enqueuer_test.go +++ b/src/jobservice/period/enqueuer_test.go @@ -96,9 +96,12 @@ func (suite *EnqueuerTestSuite) TestEnqueuer() { } }() - tk := time.NewTicker(500 * time.Millisecond) + tk := time.NewTicker(497 * time.Millisecond) defer tk.Stop() + tm := time.NewTimer(15 * time.Second) + defer tm.Stop() + for { select { case <-tk.C: @@ -109,7 +112,7 @@ func (suite *EnqueuerTestSuite) TestEnqueuer() { }, "at least one job should be scheduled for the periodic job policy") { return } - case <-time.After(15 * time.Second): + case <-tm.C: require.NoError(suite.T(), errors.New("timeout (15s): expect at 1 scheduled job but still get nothing")) return } @@ -120,7 +123,7 @@ func (suite *EnqueuerTestSuite) prepare() { now := time.Now() minute := now.Minute() - coreSpec := fmt.Sprintf("0-59 %d * * * *", minute) + coreSpec := fmt.Sprintf("0-59 %d-%d * * * *", minute, minute+2) // Prepare one p := &Policy{