Test that the entries are correctly sorted. Add a bunch of long-in-the-future entries, and an immediate entry, and ensure that the immediate entry runs immediately. Also: Test that multiple jobs run in the same instant.
(t *testing.T)
| 228 | // that the immediate entry runs immediately. |
| 229 | // Also: Test that multiple jobs run in the same instant. |
| 230 | func TestMultipleEntries(t *testing.T) { |
| 231 | wg := &sync.WaitGroup{} |
| 232 | wg.Add(2) |
| 233 | |
| 234 | cron := newWithSeconds() |
| 235 | cron.AddFunc("0 0 0 1 1 ?", func() {}) |
| 236 | cron.AddFunc("* * * * * ?", func() { wg.Done() }) |
| 237 | id1, _ := cron.AddFunc("* * * * * ?", func() { t.Fatal() }) |
| 238 | id2, _ := cron.AddFunc("* * * * * ?", func() { t.Fatal() }) |
| 239 | cron.AddFunc("0 0 0 31 12 ?", func() {}) |
| 240 | cron.AddFunc("* * * * * ?", func() { wg.Done() }) |
| 241 | |
| 242 | cron.Remove(id1) |
| 243 | cron.Start() |
| 244 | cron.Remove(id2) |
| 245 | defer cron.Stop() |
| 246 | |
| 247 | select { |
| 248 | case <-time.After(OneSecond): |
| 249 | t.Error("expected job run in proper order") |
| 250 | case <-wait(wg): |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // Test running the same job twice. |
| 255 | func TestRunningJobTwice(t *testing.T) { |