-
Notifications
You must be signed in to change notification settings - Fork 1
/
pendingqueue_test.go
46 lines (39 loc) · 1.05 KB
/
pendingqueue_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
package goscheduler
import (
"testing"
"time"
)
func TestPendingQueueSmoke(t *testing.T) {
var queue pendingQueue
queue.Init()
now := time.Now()
queue.Add(&job{
RunAt: now.Add(time.Second*4),
})
queue.Add(&job{
RunAt: now.Add(time.Second*1),
})
queue.Add(&job{
RunAt: now.Add(time.Second*3),
})
queue.Add(&job{
RunAt: now.Add(time.Second*2),
})
queue.Add(&job{
RunAt: now.Add(time.Second*5),
})
testNext(t, &queue, now.Add(time.Second * 1))
testNext(t, &queue, now.Add(time.Second * 2))
testNext(t, &queue, now.Add(time.Second * 3))
testNext(t, &queue, now.Add(time.Second * 4))
testNext(t, &queue, now.Add(time.Second * 5))
}
func testNext(t *testing.T, queue * pendingQueue, expected time.Time) {
_, j := queue.Peek()
queue.RemoveHead()
if j.RunAt != expected {
t.Logf("actual:%s, expected:%s", j.Interval, expected)
t.Log(queue.String())
t.Fatal("Pending queue not ordered")
}
}