Test timing with Entries.
(t *testing.T)
| 201 | |
| 202 | // Test timing with Entries. |
| 203 | func TestSnapshotEntries(t *testing.T) { |
| 204 | wg := &sync.WaitGroup{} |
| 205 | wg.Add(1) |
| 206 | |
| 207 | cron := New() |
| 208 | cron.AddFunc("@every 2s", func() { wg.Done() }) |
| 209 | cron.Start() |
| 210 | defer cron.Stop() |
| 211 | |
| 212 | // Cron should fire in 2 seconds. After 1 second, call Entries. |
| 213 | select { |
| 214 | case <-time.After(OneSecond): |
| 215 | cron.Entries() |
| 216 | } |
| 217 | |
| 218 | // Even though Entries was called, the cron should fire at the 2 second mark. |
| 219 | select { |
| 220 | case <-time.After(OneSecond): |
| 221 | t.Error("expected job runs at 2 second mark") |
| 222 | case <-wait(wg): |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Test that the entries are correctly sorted. |
| 227 | // Add a bunch of long-in-the-future entries, and an immediate entry, and ensure |