MCPcopy
hub / github.com/syncthing/syncthing / TestBringToFront

Function TestBringToFront

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

Source from the content-addressed store, hash-verified

123}
124
125func TestBringToFront(t *testing.T) {
126 q := newJobQueue()
127 q.Push("f1", 0, time.Time{})
128 q.Push("f2", 0, time.Time{})
129 q.Push("f3", 0, time.Time{})
130 q.Push("f4", 0, time.Time{})
131
132 _, queued, _ := q.Jobs(1, 100)
133 if diff, equal := messagediff.PrettyDiff([]string{"f1", "f2", "f3", "f4"}, queued); !equal {
134 t.Errorf("Order does not match. Diff:\n%s", diff)
135 }
136
137 q.BringToFront("f1") // corner case: does nothing
138
139 _, queued, _ = q.Jobs(1, 100)
140 if diff, equal := messagediff.PrettyDiff([]string{"f1", "f2", "f3", "f4"}, queued); !equal {
141 t.Errorf("Order does not match. Diff:\n%s", diff)
142 }
143
144 q.BringToFront("f3")
145
146 _, queued, _ = q.Jobs(1, 100)
147 if diff, equal := messagediff.PrettyDiff([]string{"f3", "f1", "f2", "f4"}, queued); !equal {
148 t.Errorf("Order does not match. Diff:\n%s", diff)
149 }
150
151 q.BringToFront("f2")
152
153 _, queued, _ = q.Jobs(1, 100)
154 if diff, equal := messagediff.PrettyDiff([]string{"f2", "f3", "f1", "f4"}, queued); !equal {
155 t.Errorf("Order does not match. Diff:\n%s", diff)
156 }
157
158 q.BringToFront("f4") // corner case: last element
159
160 _, queued, _ = q.Jobs(1, 100)
161 if diff, equal := messagediff.PrettyDiff([]string{"f4", "f2", "f3", "f1"}, queued); !equal {
162 t.Errorf("Order does not match. Diff:\n%s", diff)
163 }
164}
165
166func BenchmarkJobQueueBump(b *testing.B) {
167 files := genFiles(10000)

Callers

nothing calls this directly

Calls 4

newJobQueueFunction · 0.85
JobsMethod · 0.65
BringToFrontMethod · 0.65
PushMethod · 0.45

Tested by

no test coverage detected