MCPcopy Index your code
hub / github.com/Azure/peerd / TestSyncMapUpdate

Function TestSyncMapUpdate

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

Source from the content-addressed store, hash-verified

74}
75
76func TestSyncMapUpdate(t *testing.T) {
77 sm := NewSyncMap(10)
78 var wg sync.WaitGroup
79 addEntry := func(key string, value int) {
80 sm.Set(key, value)
81 wg.Done()
82 }
83
84 wg.Add(10)
85 for i := 0; i < 10; i++ {
86 go addEntry(fmt.Sprintf("%d", i), i)
87 }
88 wg.Wait()
89 wg.Add(10)
90 for i := 0; i < 10; i++ {
91 go addEntry(fmt.Sprintf("%d", i), i*2)
92 }
93 wg.Wait()
94
95 entry0, ok0 := sm.Get("0")
96 entry9, ok1 := sm.Get("9")
97 if !ok0 || !ok1 {
98 t.Fatalf("no matching items in map")
99 }
100 if entry0.(int) != 0 || entry9.(int) != 18 {
101 t.Fatalf("value is not correct")
102 }
103}
104
105func BenchmarkSyncMap(b *testing.B) {
106 sm := NewSyncMap(100)

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
GetMethod · 0.95
NewSyncMapFunction · 0.85

Tested by

no test coverage detected