MCPcopy
hub / github.com/cilium/cilium / TestLocalNodeStore

Function TestLocalNodeStore

pkg/node/local_node_store_test.go:34–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func TestLocalNodeStore(t *testing.T) {
35 var waitObserve sync.WaitGroup
36 var observed []uint32
37 expected := []uint32{1, 2, 3, 4, 5}
38
39 waitObserve.Add(1)
40
41 ts := testSynchronizer{identity: make(chan uint32, 1)}
42
43 // observe observes changes to the LocalNodeStore and completes
44 // waitObserve after the last change has been observed.
45 observe := func(store *LocalNodeStore) {
46 store.Observe(context.TODO(),
47 func(n LocalNode) {
48 observed = append(observed, n.NodeIdentity)
49
50 if n.NodeIdentity == expected[len(expected)-1] {
51 waitObserve.Done()
52 }
53 },
54 func(err error) {},
55 )
56 }
57
58 // update adds a start hook to the application that modifies
59 // the local node.
60 update := func(lc cell.Lifecycle, store *LocalNodeStore) {
61 lc.Append(cell.Hook{
62 OnStart: func(cell.HookContext) error {
63 // emit 2, 3, 4, 5
64 for _, i := range expected[1:] {
65 if i == 5 {
66 ts.identity <- i
67 continue
68 }
69
70 store.Update(func(n *LocalNode) {
71 n.NodeIdentity = i
72 })
73 }
74 return nil
75 },
76 })
77 }
78
79 hive := hive.New(
80 LocalNodeStoreCell,
81
82 cell.Provide(func() cmtypes.ClusterInfo {
83 return cmtypes.ClusterInfo{
84 Name: "test",
85 ID: 1,
86 }
87 }),
88 cell.Provide(func() LocalNodeSynchronizer { return ts }),
89 cell.Invoke(observe),
90 cell.Invoke(update),
91 )

Callers

nothing calls this directly

Calls 13

WaitMethod · 0.95
NewFunction · 0.92
AddMethod · 0.65
ObserveMethod · 0.65
DoneMethod · 0.65
UpdateMethod · 0.65
LoggerMethod · 0.65
StartMethod · 0.65
StopMethod · 0.65
AppendMethod · 0.45
InvokeMethod · 0.45
WithTimeoutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…