MCPcopy
hub / github.com/syncthing/syncthing / TestServiceMap

Function TestServiceMap

lib/model/service_map_test.go:18–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestServiceMap(t *testing.T) {
19 t.Parallel()
20 ctx, cancel := context.WithCancel(context.Background())
21 t.Cleanup(cancel)
22 sup := suture.NewSimple("TestServiceMap")
23 sup.ServeBackground(ctx)
24
25 t.Run("SimpleAddRemove", func(t *testing.T) {
26 t.Parallel()
27
28 sm := newServiceMap[string, *dummyService](events.NoopLogger)
29 sup.Add(sm)
30
31 // Add two services. They should start.
32
33 d1 := newDummyService()
34 d2 := newDummyService()
35
36 sm.Add("d1", d1)
37 sm.Add("d2", d2)
38
39 <-d1.started
40 <-d2.started
41
42 // Remove them. They should stop.
43
44 if !sm.Remove("d1") {
45 t.Errorf("Remove failed")
46 }
47 if !sm.Remove("d2") {
48 t.Errorf("Remove failed")
49 }
50
51 <-d1.stopped
52 <-d2.stopped
53 })
54
55 t.Run("OverwriteImpliesRemove", func(t *testing.T) {
56 t.Parallel()
57
58 sm := newServiceMap[string, *dummyService](events.NoopLogger)
59 sup.Add(sm)
60
61 d1 := newDummyService()
62 d2 := newDummyService()
63
64 // Add d1, it should start.
65
66 sm.Add("k", d1)
67 <-d1.started
68
69 // Add d2, with the same key. The previous one should stop as we're
70 // doing a replace.
71
72 sm.Add("k", d2)
73 <-d1.stopped
74 <-d2.started
75

Callers

nothing calls this directly

Calls 8

newDummyServiceFunction · 0.85
ServeBackgroundMethod · 0.80
EachMethod · 0.80
RemoveAndWaitMethod · 0.80
RemoveMethod · 0.65
GetMethod · 0.65
RunMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected