File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ func (c *Cron) run() {
155
155
e .Prev = e .Next
156
156
e .Next = e .Schedule .Next (effective )
157
157
}
158
+ continue
158
159
159
160
case newEntry := <- c .add :
160
161
c .entries = append (c .entries , newEntry )
@@ -166,6 +167,9 @@ func (c *Cron) run() {
166
167
case <- c .stop :
167
168
return
168
169
}
170
+
171
+ // 'now' should be updated after newEntry and snapshot cases.
172
+ now = time .Now ().Local ()
169
173
}
170
174
}
171
175
Original file line number Diff line number Diff line change @@ -77,6 +77,31 @@ func TestAddWhileRunning(t *testing.T) {
77
77
}
78
78
}
79
79
80
+ // Test timing with Entries.
81
+ func TestSnapshotEntries (t * testing.T ) {
82
+ wg := & sync.WaitGroup {}
83
+ wg .Add (1 )
84
+
85
+ cron := New ()
86
+ cron .AddFunc ("@every 2s" , func () { wg .Done () })
87
+ cron .Start ()
88
+ defer cron .Stop ()
89
+
90
+ // Cron should fire in 2 seconds. After 1 second, call Entries.
91
+ select {
92
+ case <- time .After (ONE_SECOND ):
93
+ cron .Entries ()
94
+ }
95
+
96
+ // Even though Entries was called, the cron should fire at the 2 second mark.
97
+ select {
98
+ case <- time .After (ONE_SECOND ):
99
+ t .FailNow ()
100
+ case <- wait (wg ):
101
+ }
102
+
103
+ }
104
+
80
105
// Test that the entries are correctly sorted.
81
106
// Add a bunch of long-in-the-future entries, and an immediate entry, and ensure
82
107
// that the immediate entry runs immediately.
You can’t perform that action at this time.
0 commit comments