fix[UT]:improve the UT cases of enqueuer (#11358)

- change the test cron spec
- use cretaed timer for timeout

Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
Steven Zou 2020-03-31 00:09:20 +08:00 committed by GitHub
parent f2beed577f
commit 3d6c65f53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,9 +96,12 @@ func (suite *EnqueuerTestSuite) TestEnqueuer() {
} }
}() }()
tk := time.NewTicker(500 * time.Millisecond) tk := time.NewTicker(497 * time.Millisecond)
defer tk.Stop() defer tk.Stop()
tm := time.NewTimer(15 * time.Second)
defer tm.Stop()
for { for {
select { select {
case <-tk.C: case <-tk.C:
@ -109,7 +112,7 @@ func (suite *EnqueuerTestSuite) TestEnqueuer() {
}, "at least one job should be scheduled for the periodic job policy") { }, "at least one job should be scheduled for the periodic job policy") {
return 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")) require.NoError(suite.T(), errors.New("timeout (15s): expect at 1 scheduled job but still get nothing"))
return return
} }
@ -120,7 +123,7 @@ func (suite *EnqueuerTestSuite) prepare() {
now := time.Now() now := time.Now()
minute := now.Minute() minute := now.Minute()
coreSpec := fmt.Sprintf("0-59 %d * * * *", minute) coreSpec := fmt.Sprintf("0-59 %d-%d * * * *", minute, minute+2)
// Prepare one // Prepare one
p := &Policy{ p := &Policy{