MCPcopy Index your code
hub / github.com/syncthing/syncthing / TestJobQueue

Function TestJobQueue

lib/model/queue_test.go:19–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestJobQueue(t *testing.T) {
20 // Some random actions
21 q := newJobQueue()
22 q.Push("f1", 0, time.Time{})
23 q.Push("f2", 0, time.Time{})
24 q.Push("f3", 0, time.Time{})
25 q.Push("f4", 0, time.Time{})
26
27 progress, queued, _ := q.Jobs(1, 100)
28 if len(progress) != 0 || len(queued) != 4 {
29 t.Fatal("Wrong length", len(progress), len(queued))
30 }
31
32 for i := 1; i < 5; i++ {
33 n, ok := q.Pop()
34 if !ok || n != fmt.Sprintf("f%d", i) {
35 t.Fatal("Wrong element")
36 }
37 progress, queued, _ = q.Jobs(1, 100)
38 if len(progress) != 1 || len(queued) != 3 {
39 t.Log(progress)
40 t.Log(queued)
41 t.Fatal("Wrong length")
42 }
43
44 q.Done(n)
45 progress, queued, _ = q.Jobs(1, 100)
46 if len(progress) != 0 || len(queued) != 3 {
47 t.Fatal("Wrong length", len(progress), len(queued))
48 }
49
50 q.Push(n, 0, time.Time{})
51 progress, queued, _ = q.Jobs(1, 100)
52 if len(progress) != 0 || len(queued) != 4 {
53 t.Fatal("Wrong length")
54 }
55
56 q.Done("f5") // Does not exist
57 progress, queued, _ = q.Jobs(1, 100)
58 if len(progress) != 0 || len(queued) != 4 {
59 t.Fatal("Wrong length")
60 }
61 }
62
63 if len(q.progress) > 0 || len(q.queued) != 4 {
64 t.Fatal("Wrong length")
65 }
66
67 for i := 4; i > 0; i-- {
68 progress, queued, _ = q.Jobs(1, 100)
69 if len(progress) != 4-i || len(queued) != i {
70 t.Fatal("Wrong length")
71 }
72
73 s := fmt.Sprintf("f%d", i)
74
75 q.BringToFront(s)
76 progress, queued, _ = q.Jobs(1, 100)

Callers

nothing calls this directly

Calls 8

newJobQueueFunction · 0.85
FatalMethod · 0.80
DoneMethod · 0.80
JobsMethod · 0.65
LogMethod · 0.65
BringToFrontMethod · 0.65
PushMethod · 0.45
PopMethod · 0.45

Tested by

no test coverage detected