-
Notifications
You must be signed in to change notification settings - Fork 3
/
scheduler_test.go
698 lines (584 loc) · 18.1 KB
/
scheduler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
package scheduler
import (
"fmt"
"github.com/GoFarsi/scheduler/helper"
"github.com/GoFarsi/scheduler/types"
"github.com/stretchr/testify/assert"
"log"
"sync"
"testing"
"time"
)
func task() {
fmt.Println("I am a running job.")
}
func taskWithParams(a int, b string) {
fmt.Println(a, b)
}
func TestSecond(t *testing.T) {
scheduler := New()
jb := scheduler.Every(1).Seconds()
testJobWithInterval(t, scheduler, jb, 1)
}
func TestSeconds(t *testing.T) {
sched := New()
jb := sched.Every(2).Seconds()
testJobWithInterval(t, sched, jb, 2)
}
func testJobWithInterval(t *testing.T, sched *Scheduler, jb *Job, expectedTimeBetweenRuns int64) {
jobDone := make(chan bool)
executionTimes := make([]int64, 0)
numberOfIterations := 2
jb.Do(func() {
executionTimes = append(executionTimes, time.Now().Unix())
if len(executionTimes) >= numberOfIterations {
jobDone <- true
}
})
stop := sched.Start()
<-jobDone // Wait job done
close(stop)
assert.Equal(t, numberOfIterations, len(executionTimes), "Did not run as many times as expected")
for i := 1; i < numberOfIterations; i++ {
durationBetweenExecutions := executionTimes[i] - executionTimes[i-1]
assert.Equal(t, expectedTimeBetweenRuns, durationBetweenExecutions, "Tasks are not completed within the expected timeframe")
}
}
func TestSafeExecution(t *testing.T) {
sched := New()
success := false
var wc sync.WaitGroup
wc.Add(1)
sched.Every(1).Second().Do(func(mutableValue *bool) {
*mutableValue = !*mutableValue
wc.Done()
}, &success)
sched.RunAll()
wc.Wait()
assert.Equal(t, true, success, "Task did not get called")
}
func TestSafeExecutionWithPanic(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Errorf("Unexpected internal panic occurred: %s", r)
}
}()
sched := New()
sched.Every(1).Second().DoJobSafely(func() {
log.Panic("I am panicking!")
})
sched.RunAll()
}
func TestScheduled(t *testing.T) {
n := New()
n.Every(1).Second().Do(task)
if !n.Scheduled(task) {
t.Fatal("Task was scheduled but function couldn't find it")
}
}
func TestScheduler_Weekdays(t *testing.T) {
scheduler := New()
job1 := scheduler.Every(1).Monday().At("23:59")
job2 := scheduler.Every(1).Wednesday().At("23:59")
job1.Do(task)
job2.Do(task)
t.Logf("job1 scheduled for %s", job1.NextScheduledTime())
t.Logf("job2 scheduled for %s", job2.NextScheduledTime())
assert.NotEqual(t, job1.NextScheduledTime(), job2.NextScheduledTime(), "Two jobs scheduled at the same time on two different weekdays should never run at the same time")
}
func TestScheduler_WeekdaysTodayAfter(t *testing.T) {
scheduler := New()
now := time.Now()
timeToSchedule := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-1, 0, 0, time.Local)
job := callTodaysWeekday(scheduler.Every(1)).At(fmt.Sprintf("%02d:%02d", timeToSchedule.Hour(), timeToSchedule.Minute()))
job.Do(task)
t.Logf("job is scheduled for %s", job.NextScheduledTime())
if job.NextScheduledTime().Weekday() != timeToSchedule.Weekday() {
t.Errorf("Job scheduled for current weekday for earlier time, should still be scheduled for current weekday (but next week)")
}
nextWeek := time.Date(now.Year(), now.Month(), now.Day()+7, now.Hour(), now.Minute()-1, 0, 0, time.Local)
if !job.NextScheduledTime().Equal(nextWeek) {
t.Errorf("Job should be scheduled for the correct time next week.\nGot %+v, expected %+v", job.NextScheduledTime(), nextWeek)
}
}
func TestScheduler_JobLocsSetProperly(t *testing.T) {
defaultScheduledJob := NewJob(10)
assert.Equal(t, defaultScheduledJob.TimeLocation, time.Local)
defaultScheduledJobFromScheduler := Every(10)
assert.Equal(t, defaultScheduledJobFromScheduler.TimeLocation, time.Local)
laLocation, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
t.Fatalf("unable to load America/Los_Angeles time location")
}
ChangeTimeLocation(laLocation)
modifiedGlobalLocJob := NewJob(10)
assert.Equal(t, modifiedGlobalLocJob.TimeLocation, laLocation)
modifiedGlobalLocJobFromScheduler := Every(10)
assert.Equal(t, modifiedGlobalLocJobFromScheduler.TimeLocation, laLocation)
chiLocation, err := time.LoadLocation("America/Chicago")
if err != nil {
t.Fatalf("unable to load America/Chicago time location")
}
scheduler := New()
scheduler.ChangeLocation(chiLocation)
modifiedGlobalLocJobFromScheduler = scheduler.Every(10)
assert.Equal(t, modifiedGlobalLocJobFromScheduler.TimeLocation, chiLocation)
// other tests depend on global state :(
ChangeTimeLocation(time.Local)
}
func TestScheduleNextRunLoc(t *testing.T) {
laLocation, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
t.Fatalf("unable to load America/Los_Angeles time location")
}
sched := New()
sched.ChangeLocation(time.UTC)
job := sched.Every(1).Day().At("20:44")
// job just ran (this is 20:45 UTC), so next run should be tomorrow
today := time.Now().In(laLocation)
job.LastRun = time.Date(today.Year(), today.Month(), today.Day(), 13, 45, 0, 0, laLocation)
job.Do(task)
tomorrow := today.AddDate(0, 0, 1)
assert.Equal(t, 20, job.NextScheduledTime().UTC().Hour())
assert.Equal(t, 44, job.NextScheduledTime().UTC().Minute())
assert.Equal(t, tomorrow.Day(), job.NextScheduledTime().UTC().Day())
}
func TestScheduleNextRunFromNow(t *testing.T) {
now := time.Now()
sched := New()
sched.ChangeLocation(time.UTC)
job := sched.Every(1).Hour().From(helper.NextTick())
job.Do(task)
next := job.NextScheduledTime()
nextRounded := time.Date(next.Year(), next.Month(), next.Day(), next.Hour(), next.Minute(), next.Second(), 0, time.UTC)
expected := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.UTC).Add(time.Second)
assert.Exactly(t, expected, nextRounded)
}
// This is to ensure that if you schedule a job for today's weekday, and the time hasn't yet passed, the next run time
// will be scheduled for today.
func TestScheduler_WeekdaysTodayBefore(t *testing.T) {
scheduler := New()
now := time.Now()
timeToSchedule := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()+1, 0, 0, time.Local)
job := callTodaysWeekday(scheduler.Every(1)).At(fmt.Sprintf("%02d:%02d", timeToSchedule.Hour(), timeToSchedule.Minute()))
job.Do(task)
t.Logf("job is scheduled for %s", job.NextScheduledTime())
if !job.NextScheduledTime().Equal(timeToSchedule) {
t.Error("Job should be run today, at the set time.")
}
}
func Test_formatTime(t *testing.T) {
tests := []struct {
name string
args string
wantHour int
wantMin int
wantSec int
wantErr bool
}{
{
name: "normal",
args: "16:18",
wantHour: 16,
wantMin: 18,
wantErr: false,
},
{
name: "normal_with_second",
args: "6:18:01",
wantHour: 6,
wantMin: 18,
wantSec: 1,
wantErr: false,
},
{
name: "not_a_number",
args: "e:18",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "out_of_range_hour",
args: "25:18",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "out_of_range_minute",
args: "23:60",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "wrong_format",
args: "19:18:17:17",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "wrong_minute",
args: "19:1e",
wantHour: 19,
wantMin: 0,
wantErr: true,
},
{
name: "wrong_hour",
args: "1e:10",
wantHour: 11,
wantMin: 0,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHour, gotMin, gotSec, err := helper.TimeFormat(tt.args)
if tt.wantErr {
assert.NotEqual(t, nil, err, tt.args)
return
}
assert.Equal(t, tt.wantHour, gotHour, tt.args)
assert.Equal(t, tt.wantMin, gotMin, tt.args)
if tt.wantSec != 0 {
assert.Equal(t, tt.wantSec, gotSec)
} else {
assert.Zero(t, gotSec)
}
})
}
}
// utility function for testing the weekday functions *on* the current weekday.
func callTodaysWeekday(job *Job) *Job {
switch time.Now().Weekday() {
case 0:
job.Sunday()
case 1:
job.Monday()
case 2:
job.Tuesday()
case 3:
job.Wednesday()
case 4:
job.Thursday()
case 5:
job.Friday()
case 6:
job.Saturday()
}
return job
}
func TestScheduler_Remove(t *testing.T) {
scheduler := New()
scheduler.Every(1).Minute().Do(task)
scheduler.Every(1).Minute().Do(taskWithParams, 1, "hello")
assert.Equal(t, 2, scheduler.Len(), "Incorrect number of jobs")
scheduler.Remove(task)
assert.Equal(t, 1, scheduler.Len(), "Incorrect number of jobs after removing 1 job")
scheduler.Remove(task)
assert.Equal(t, 1, scheduler.Len(), "Incorrect number of jobs after removing non-existent job")
}
func TestScheduler_RemoveByRef(t *testing.T) {
scheduler := New()
job1 := scheduler.Every(1).Minute()
job1.Do(task)
job2 := scheduler.Every(1).Minute()
job2.Do(taskWithParams, 1, "hello")
assert.Equal(t, 2, scheduler.Len(), "Incorrect number of jobs")
scheduler.RemoveByRef(job1)
assert.ElementsMatch(t, []*Job{job2}, scheduler.Jobs())
}
func TestTaskAt(t *testing.T) {
// Create new scheduler to have clean test env
s := New()
// Schedule to run in next minute
now := time.Now()
// Schedule every day At
startAt := fmt.Sprintf("%02d:%02d", now.Hour(), now.Add(time.Minute).Minute())
dayJob := s.Every(1).Day().At(startAt)
dayJobDone := make(chan bool, 1)
dayJob.Do(func() {
dayJobDone <- true
})
// Expected start time
expectedStartTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Add(time.Minute).Minute(), 0, 0, types.TimeZone)
nextRun := dayJob.NextScheduledTime()
assert.Equal(t, expectedStartTime, nextRun)
sStop := s.Start()
<-dayJobDone // Wait job done
close(sStop)
time.Sleep(time.Second) // wait for scheduler to reschedule job
// Expected next start time 1 day after
expectedNextRun := expectedStartTime.AddDate(0, 0, 1)
nextRun = dayJob.NextScheduledTime()
assert.Equal(t, expectedNextRun, nextRun)
}
func TestTaskAtFuture(t *testing.T) {
// Create new scheduler to have clean test env
s := New()
now := time.Now()
// Schedule to run in next minute
nextMinuteTime := now.Add(time.Duration(1 * time.Minute))
startAt := fmt.Sprintf("%02d:%02d", nextMinuteTime.Hour(), nextMinuteTime.Minute())
dayJob := s.Every(1).Day().At(startAt)
shouldBeFalse := false
dayJob.Do(func() {
shouldBeFalse = true
})
// Check first run
expectedStartTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Add(time.Minute).Minute(), 0, 0, types.TimeZone)
nextRun := dayJob.NextScheduledTime()
assert.Equal(t, expectedStartTime, nextRun)
s.RunPending()
// Check next run's scheduled time
nextRun = dayJob.NextScheduledTime()
assert.Equal(t, expectedStartTime, nextRun)
assert.Equal(t, false, shouldBeFalse, "Day job was not expected to run as it was in the future")
}
func TestDaily(t *testing.T) {
now := time.Now()
// Create new scheduler to have clean test env
s := New()
// schedule next run 1 day
dayJob := s.Every(1).Day()
dayJob.NextJobRun()
tomorrow := now.AddDate(0, 0, 1)
expectedTime := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, expectedTime, dayJob.NextRun)
// schedule next run 2 days
dayJob = s.Every(2).Days()
dayJob.NextJobRun()
twoDaysFromNow := now.AddDate(0, 0, 2)
expectedTime = time.Date(twoDaysFromNow.Year(), twoDaysFromNow.Month(), twoDaysFromNow.Day(), 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, expectedTime, dayJob.NextRun)
// Job running longer than next schedule 1day 2 hours
dayJob = s.Every(1).Day()
twoHoursFromNow := now.Add(2 * time.Hour)
dayJob.LastRun = time.Date(twoHoursFromNow.Year(), twoHoursFromNow.Month(), twoHoursFromNow.Day(), twoHoursFromNow.Hour(), 0, 0, 0, types.TimeZone)
dayJob.NextJobRun()
expectedTime = time.Date(twoHoursFromNow.Year(), twoHoursFromNow.Month(), twoHoursFromNow.AddDate(0, 0, 1).Day(), 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, expectedTime, dayJob.NextRun)
// At() 2 hours before now
twoHoursBefore := now.Add(time.Duration(-2 * time.Hour))
startAt := fmt.Sprintf("%02d:%02d", twoHoursBefore.Hour(), twoHoursBefore.Minute())
dayJob = s.Every(1).Day().At(startAt)
dayJob.NextJobRun()
expectedTime = time.Date(twoHoursBefore.Year(), twoHoursBefore.Month(),
twoHoursBefore.AddDate(0, 0, 1).Day(),
twoHoursBefore.Hour(), twoHoursBefore.Minute(), 0, 0, types.TimeZone)
assert.Equal(t, expectedTime, dayJob.NextRun)
}
func TestWeekdayAfterToday(t *testing.T) {
now := time.Now()
// Create new scheduler to have clean test env
s := New()
// Schedule job at next week day
var weekJob *Job
switch now.Weekday() {
case time.Monday:
weekJob = s.Every(1).Tuesday()
case time.Tuesday:
weekJob = s.Every(1).Wednesday()
case time.Wednesday:
weekJob = s.Every(1).Thursday()
case time.Thursday:
weekJob = s.Every(1).Friday()
case time.Friday:
weekJob = s.Every(1).Saturday()
case time.Saturday:
weekJob = s.Every(1).Sunday()
case time.Sunday:
weekJob = s.Every(1).Monday()
}
// First run
weekJob.NextJobRun()
exp := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, exp, weekJob.NextRun)
// Simulate job run 7 days before
weekJob.LastRun = weekJob.NextRun.AddDate(0, 0, -7)
// Next run
weekJob.NextJobRun()
exp = time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, exp, weekJob.NextRun)
}
func TestWeekdayBeforeToday(t *testing.T) {
now := time.Now()
// Create new scheduler to have clean test env
s := New()
// Schedule job at day before
var weekJob *Job
switch now.Weekday() {
case time.Monday:
weekJob = s.Every(1).Sunday()
case time.Tuesday:
weekJob = s.Every(1).Monday()
case time.Wednesday:
weekJob = s.Every(1).Tuesday()
case time.Thursday:
weekJob = s.Every(1).Wednesday()
case time.Friday:
weekJob = s.Every(1).Thursday()
case time.Saturday:
weekJob = s.Every(1).Friday()
case time.Sunday:
weekJob = s.Every(1).Saturday()
}
weekJob.NextJobRun()
sixDaysFromNow := now.AddDate(0, 0, 6)
exp := time.Date(sixDaysFromNow.Year(), sixDaysFromNow.Month(), sixDaysFromNow.Day(), 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, exp, weekJob.NextRun)
// Simulate job run 7 days before
weekJob.LastRun = weekJob.NextRun.AddDate(0, 0, -7)
// Next run
weekJob.NextJobRun()
exp = time.Date(sixDaysFromNow.Year(), sixDaysFromNow.Month(), sixDaysFromNow.Day(), 0, 0, 0, 0, types.TimeZone)
assert.Equal(t, exp, weekJob.NextRun)
}
func TestWeekdayAt(t *testing.T) {
now := time.Now()
hour := now.Hour()
minute := now.Minute()
startAt := fmt.Sprintf("%02d:%02d", hour, minute)
// Create new scheduler to have clean test env
s := New()
// Schedule job at next week day
var weekJob *Job
switch now.Weekday() {
case time.Monday:
weekJob = s.Every(1).Tuesday().At(startAt)
case time.Tuesday:
weekJob = s.Every(1).Wednesday().At(startAt)
case time.Wednesday:
weekJob = s.Every(1).Thursday().At(startAt)
case time.Thursday:
weekJob = s.Every(1).Friday().At(startAt)
case time.Friday:
weekJob = s.Every(1).Saturday().At(startAt)
case time.Saturday:
weekJob = s.Every(1).Sunday().At(startAt)
case time.Sunday:
weekJob = s.Every(1).Monday().At(startAt)
}
// First run
weekJob.NextJobRun()
exp := time.Date(now.Year(), now.Month(), now.AddDate(0, 0, 1).Day(), hour, minute, 0, 0, types.TimeZone)
assert.Equal(t, exp, weekJob.NextRun)
// Simulate job run 7 days before
weekJob.LastRun = weekJob.NextRun.AddDate(0, 0, -7)
// Next run
weekJob.NextJobRun()
exp = time.Date(now.Year(), now.Month(), now.AddDate(0, 0, 1).Day(), hour, minute, 0, 0, types.TimeZone)
assert.Equal(t, exp, weekJob.NextRun)
}
type lockerMock struct {
cache map[string]struct{}
l sync.Mutex
}
func (l *lockerMock) Lock(key string) (bool, error) {
l.l.Lock()
defer l.l.Unlock()
if _, ok := l.cache[key]; ok {
return false, nil
}
l.cache[key] = struct{}{}
return true, nil
}
func (l *lockerMock) Unlock(key string) error {
l.l.Lock()
defer l.l.Unlock()
delete(l.cache, key)
return nil
}
func TestSetLocker(t *testing.T) {
if jobLocker != nil {
t.Fail()
t.Log("Expected locker to not be set by default")
}
SetLocker(&lockerMock{})
if jobLocker == nil {
t.Fail()
t.Log("Expected locker to be set")
}
}
type lockerResult struct {
key string
cycle int
s, e time.Time
}
func TestLocker(t *testing.T) {
l := sync.Mutex{}
result := make([]lockerResult, 0)
task := func(key string, i int) {
s := time.Now()
time.Sleep(time.Millisecond * 100)
e := time.Now()
l.Lock()
result = append(result, lockerResult{
key: key,
cycle: i,
s: s,
e: e,
})
l.Unlock()
}
SetLocker(&lockerMock{
make(map[string]struct{}),
sync.Mutex{},
})
for i := 0; i < 5; i++ {
s1 := New()
s1.Every(1).Seconds().Lock().Do(task, "A", i)
s2 := New()
s2.Every(1).Seconds().Lock().Do(task, "B", i)
s3 := New()
s3.Every(1).Seconds().Lock().Do(task, "C", i)
stop1 := s1.Start()
stop2 := s2.Start()
stop3 := s3.Start()
time.Sleep(time.Millisecond * 100)
close(stop1)
close(stop2)
close(stop3)
for i := 0; i < len(result)-1; i++ {
for j := i + 1; j < len(result); j++ {
iBefJ := result[i].s.Before(result[j].s) && result[i].e.Before(result[j].s)
jBefI := result[j].s.Before(result[i].s) && result[j].e.Before(result[i].s)
if !iBefJ && !jBefI {
t.Fatalf("\n2 operations ran concurrently:\n%s\n%d\n%s\n%s\n**********\n%s\n%d\n%s\n%s\n",
result[i].key, result[i].cycle, result[i].s, result[i].e,
result[j].key, result[j].cycle, result[j].s, result[j].e)
}
}
}
}
}
func TestGetAllJobs(t *testing.T) {
defaultScheduler = New()
Every(1).Minute().Do(task)
Every(2).Minutes().Do(task)
Every(3).Minutes().Do(task)
Every(4).Minutes().Do(task)
js := Jobs()
assert.Len(t, js, 4)
}
func TestTags(t *testing.T) {
j := Every(1).Minute()
j.Tag("some")
j.Tag("tag")
j.Tag("more")
j.Tag("tags")
assert.ElementsMatch(t, j.TagList(), []string{"tags", "tag", "more", "some"})
j.UnTag("more")
assert.ElementsMatch(t, j.TagList(), []string{"tags", "tag", "some"})
}
func TestGetAt(t *testing.T) {
j := Every(1).Minute().At("10:30")
assert.Equal(t, "10:30", j.GetAtTime())
}
func TestGetWeekday(t *testing.T) {
j := Every(1).Weekday(time.Wednesday)
assert.Equal(t, time.Wednesday, j.GetWeekday())
}