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

Function TestDeviceActivity

lib/model/deviceactivity_test.go:15–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestDeviceActivity(t *testing.T) {
16 n0 := Availability{protocol.DeviceID([32]byte{1, 2, 3, 4}), false}
17 n1 := Availability{protocol.DeviceID([32]byte{5, 6, 7, 8}), true}
18 n2 := Availability{protocol.DeviceID([32]byte{9, 10, 11, 12}), false}
19 devices := []Availability{n0, n1, n2}
20 na := newDeviceActivity()
21
22 if lb := na.leastBusy(devices); lb != 0 {
23 t.Errorf("Least busy device should be n0 (%v) not %v", n0, lb)
24 }
25 if lb := na.leastBusy(devices); lb != 0 {
26 t.Errorf("Least busy device should still be n0 (%v) not %v", n0, lb)
27 }
28
29 lb := na.leastBusy(devices)
30 na.using(devices[lb])
31 if lb := na.leastBusy(devices); lb != 1 {
32 t.Errorf("Least busy device should be n1 (%v) not %v", n1, lb)
33 }
34 lb = na.leastBusy(devices)
35 na.using(devices[lb])
36 if lb := na.leastBusy(devices); lb != 2 {
37 t.Errorf("Least busy device should be n2 (%v) not %v", n2, lb)
38 }
39
40 lb = na.leastBusy(devices)
41 na.using(devices[lb])
42 if lb := na.leastBusy(devices); lb != 0 {
43 t.Errorf("Least busy device should be n0 (%v) not %v", n0, lb)
44 }
45
46 na.done(n1)
47 if lb := na.leastBusy(devices); lb != 1 {
48 t.Errorf("Least busy device should be n1 (%v) not %v", n1, lb)
49 }
50
51 na.done(n2)
52 if lb := na.leastBusy(devices); lb != 1 {
53 t.Errorf("Least busy device should still be n1 (%v) not %v", n1, lb)
54 }
55
56 na.done(n0)
57 if lb := na.leastBusy(devices); lb != 0 {
58 t.Errorf("Least busy device should be n0 (%v) not %v", n0, lb)
59 }
60}

Callers

nothing calls this directly

Calls 5

DeviceIDTypeAlias · 0.92
newDeviceActivityFunction · 0.85
leastBusyMethod · 0.80
usingMethod · 0.80
doneMethod · 0.45

Tested by

no test coverage detected