Skip to content

Commit

Permalink
cron_test: fix bug in tests leading to flakiness
Browse files Browse the repository at this point in the history
Test[Non]LocalTimezone was occasionally specifying an invalid cron spec seconds
field of "59,60", which caused it to subsequently fail. Since rolling the cron
spec forward is hard, in those cases we instead sleep for a couple seconds to
avoid the scenario.

Fixes robfig#205
  • Loading branch information
Rob Figueiredo committed Jul 11, 2019
1 parent 1cba5e6 commit 0275a3e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ func TestLocalTimezone(t *testing.T) {
wg.Add(2)

now := time.Now()
// FIX: Issue #205
// This calculation doesn't work in seconds 58 or 59.
// Take the easy way out and sleep.
if now.Second() >= 58 {
time.Sleep(2 * time.Second)
now = time.Now()
}
spec := fmt.Sprintf("%d,%d %d %d %d %d ?",
now.Second()+1, now.Second()+2, now.Minute(), now.Hour(), now.Day(), now.Month())

Expand Down Expand Up @@ -324,6 +331,13 @@ func TestNonLocalTimezone(t *testing.T) {
}

now := time.Now().In(loc)
// FIX: Issue #205
// This calculation doesn't work in seconds 58 or 59.
// Take the easy way out and sleep.
if now.Second() >= 58 {
time.Sleep(2 * time.Second)
now = time.Now().In(loc)
}
spec := fmt.Sprintf("%d,%d %d %d %d %d ?",
now.Second()+1, now.Second()+2, now.Minute(), now.Hour(), now.Day(), now.Month())

Expand Down

0 comments on commit 0275a3e

Please sign in to comment.