MCPcopy Create free account
hub / github.com/Azure/peerd / TestSyncMapAddDelete

Function TestSyncMapAddDelete

pkg/cache/syncmap_test.go:43–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestSyncMapAddDelete(t *testing.T) {
44 sm := NewSyncMap(10)
45 var wg sync.WaitGroup
46
47 addEntry := func(key string, value int) {
48 sm.Set(key, value)
49 wg.Done()
50 }
51
52 deleteEntry := func(key string) {
53 sm.Delete(key)
54 wg.Done()
55 }
56
57 wg.Add(10)
58 for i := 0; i < 10; i++ {
59 go addEntry(fmt.Sprintf("%d", i), i)
60 }
61
62 wg.Wait()
63
64 wg.Add(10)
65 for i := 0; i < 10; i++ {
66 go deleteEntry(fmt.Sprintf("%d", i))
67 }
68
69 wg.Wait()
70 mapLen := len(*sm.mapObj)
71 if mapLen != 0 {
72 t.Fatalf("unexpected length of map: %d", mapLen)
73 }
74}
75
76func TestSyncMapUpdate(t *testing.T) {
77 sm := NewSyncMap(10)

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
DeleteMethod · 0.95
NewSyncMapFunction · 0.85

Tested by

no test coverage detected