MCPcopy
hub / github.com/lxzan/gws / TestConcurrentMap

Function TestConcurrentMap

session_storage_test.go:98–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestConcurrentMap(t *testing.T) {
99 var as = assert.New(t)
100 var m1 = make(map[string]any)
101 var m2 = NewConcurrentMap[string, uint32]()
102 var count = internal.AlphabetNumeric.Intn(1000)
103 for i := 0; i < count; i++ {
104 var key = string(internal.AlphabetNumeric.Generate(10))
105 var val = internal.AlphabetNumeric.Uint32()
106 m1[key] = val
107 m2.Store(key, val)
108 }
109
110 var keys = make([]string, 0)
111 for k, _ := range m1 {
112 keys = append(keys, k)
113 }
114 for i := 0; i < len(keys)/2; i++ {
115 delete(m1, keys[i])
116 m2.Delete(keys[i])
117 }
118
119 for k, v := range m1 {
120 v1, ok := m2.Load(k)
121 as.Equal(true, ok)
122 as.Equal(v, v1)
123 }
124 as.Equal(len(m1), m2.Len())
125}
126
127func TestConcurrentMap_Range(t *testing.T) {
128 var as = assert.New(t)

Callers

nothing calls this directly

Calls 8

NewConcurrentMapFunction · 0.85
IntnMethod · 0.80
GenerateMethod · 0.80
Uint32Method · 0.80
StoreMethod · 0.65
DeleteMethod · 0.65
LoadMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected