@@ -2325,6 +2325,59 @@ func TestScheduler_AtTimesJob(t *testing.T) {
2325
2325
},
2326
2326
},
2327
2327
},
2328
+
2329
+ {
2330
+ name : "two runs in the future - order is maintained even if times are provided out of order - deduplication" ,
2331
+ atTimes : []time.Time {n .Add (3 * time .Millisecond ), n .Add (1 * time .Millisecond ), n .Add (1 * time .Millisecond ), n .Add (3 * time .Millisecond )},
2332
+ fakeClock : clockwork .NewFakeClockAt (n ),
2333
+ advanceAndAsserts : []func (t * testing.T , j Job , clock clockwork.FakeClock , runs * atomic.Uint32 ){
2334
+ func (t * testing.T , j Job , clock clockwork.FakeClock , runs * atomic.Uint32 ) {
2335
+ require .Equal (t , uint32 (0 ), runs .Load ())
2336
+
2337
+ // last not initialized
2338
+ lastRunAt , err := j .LastRun ()
2339
+ require .NoError (t , err )
2340
+ require .Equal (t , time.Time {}, lastRunAt )
2341
+
2342
+ // next is now
2343
+ nextRunAt , err := j .NextRun ()
2344
+ require .NoError (t , err )
2345
+ require .Equal (t , n .Add (1 * time .Millisecond ), nextRunAt )
2346
+
2347
+ // advance and eventually run
2348
+ clock .Advance (2 * time .Millisecond )
2349
+ require .Eventually (t , func () bool {
2350
+ return assert .Equal (t , uint32 (1 ), runs .Load ())
2351
+ }, 3 * time .Second , 100 * time .Millisecond )
2352
+
2353
+ // last was run
2354
+ lastRunAt , err = j .LastRun ()
2355
+ require .NoError (t , err )
2356
+ require .WithinDuration (t , n .Add (1 * time .Millisecond ), lastRunAt , 1 * time .Millisecond )
2357
+
2358
+ nextRunAt , err = j .NextRun ()
2359
+ require .NoError (t , err )
2360
+ require .Equal (t , n .Add (3 * time .Millisecond ), nextRunAt )
2361
+ },
2362
+
2363
+ func (t * testing.T , j Job , clock clockwork.FakeClock , runs * atomic.Uint32 ) {
2364
+ // advance and eventually run
2365
+ clock .Advance (2 * time .Millisecond )
2366
+ require .Eventually (t , func () bool {
2367
+ return assert .Equal (t , uint32 (2 ), runs .Load ())
2368
+ }, 3 * time .Second , 100 * time .Millisecond )
2369
+
2370
+ // last was run
2371
+ lastRunAt , err := j .LastRun ()
2372
+ require .NoError (t , err )
2373
+ require .WithinDuration (t , n .Add (3 * time .Millisecond ), lastRunAt , 1 * time .Millisecond )
2374
+
2375
+ nextRunAt , err := j .NextRun ()
2376
+ require .NoError (t , err )
2377
+ require .Equal (t , time.Time {}, nextRunAt )
2378
+ },
2379
+ },
2380
+ },
2328
2381
}
2329
2382
2330
2383
for _ , tt := range tests {
0 commit comments