MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestTracker

Function TestTracker

kayak/tracker_test.go:43–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestTracker(t *testing.T) {
44 Convey("test tracker", t, func(c C) {
45 nodeID1 := proto.NodeID("000005f4f22c06f76c43c4f48d5a7ec1309cc94030cbf9ebae814172884ac8b5")
46 nodeID2 := proto.NodeID("000005aa62048f85da4ae9698ed59c14ec0d48a88a07c15a32265634e7e64ade")
47 r := &Runtime{
48 applyRPCMethod: "test",
49 followers: []proto.NodeID{
50 nodeID1,
51 nodeID2,
52 },
53 }
54
55 fakeTrackerCallerMap := map[proto.NodeID]Caller{
56 nodeID1: &fakeTrackerCaller{c: c},
57 nodeID2: &fakeTrackerCaller{c: c},
58 }
59 r.TrackerNewCallerFunc = func(target proto.NodeID) Caller {
60 return fakeTrackerCallerMap[target]
61 }
62
63 t1 := newTracker(r, 1, 0)
64 t1.send()
65 _, meets, _ := t1.get(context.Background())
66 So(meets, ShouldBeTrue)
67
68 t2 := newTracker(r, 1, 1)
69 t2.send()
70 r2, meets, _ := t2.get(context.Background())
71 So(r2, ShouldNotBeEmpty)
72 So(meets, ShouldBeTrue)
73
74 t3 := newTracker(r, 1, 1)
75 t3.send()
76 ctx1, cancelCtx1 := context.WithTimeout(context.Background(), time.Millisecond*1)
77 defer cancelCtx1()
78 r3, meets, finished := t3.get(ctx1)
79 So(r3, ShouldBeEmpty)
80 So(meets, ShouldBeFalse)
81 So(finished, ShouldBeFalse)
82
83 r3, meets, finished = t3.get(context.Background())
84 So(r3, ShouldNotBeEmpty)
85 So(meets, ShouldBeTrue)
86
87 t4 := newTracker(r, 1, 2)
88 t4.send()
89 r4, meets, finished := t4.get(context.Background())
90 So(r4, ShouldHaveLength, 2)
91 So(meets, ShouldBeTrue)
92 So(finished, ShouldBeTrue)
93
94 t5 := newTracker(r, 2, 2)
95 t5.send()
96 ctx2, cancelCtx2 := context.WithTimeout(context.Background(), time.Millisecond*1)
97 defer cancelCtx2()
98 r5, meets, finished := t5.get(ctx2)
99 So(r5, ShouldBeEmpty)
100 So(meets, ShouldBeFalse)

Callers

nothing calls this directly

Calls 5

NodeIDTypeAlias · 0.92
newTrackerFunction · 0.85
sendMethod · 0.80
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected