MCPcopy
hub / github.com/olric-data/olric / TestDMap_Atomic_IncrByFloat

Function TestDMap_Atomic_IncrByFloat

internal/dmap/atomic_test.go:196–235  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func TestDMap_Atomic_IncrByFloat(t *testing.T) {
197 cluster := testcluster.New(NewService)
198 s := cluster.AddMember(nil).(*Service)
199 defer cluster.Shutdown()
200
201 var wg sync.WaitGroup
202 var start chan struct{}
203 key := "incrbyfloat"
204
205 ctx := context.Background()
206 incrByFloat := func(dm *DMap) {
207 <-start
208 defer wg.Done()
209
210 _, err := dm.IncrByFloat(ctx, key, 1.2)
211 if err != nil {
212 s.log.V(2).Printf("[ERROR] Failed to call IncrByFloat: %v", err)
213 return
214 }
215 }
216
217 dm, err := s.NewDMap("atomic_test")
218 require.NoError(t, err)
219
220 start = make(chan struct{})
221 for i := 0; i < 100; i++ {
222 wg.Add(1)
223 go incrByFloat(dm)
224 }
225 close(start)
226 wg.Wait()
227
228 gr, err := dm.Get(ctx, key)
229 require.NoError(t, err)
230
231 var res float64
232 err = resp.Scan(gr.Value(), &res)
233 require.NoError(t, err)
234 require.Equal(t, 120.0000000000002, res)
235}
236
237func TestDMap_incrCommandHandler(t *testing.T) {
238 cluster := testcluster.New(NewService)

Callers

nothing calls this directly

Calls 11

IncrByFloatMethod · 0.95
GetMethod · 0.95
NewFunction · 0.92
ScanFunction · 0.92
AddMemberMethod · 0.80
PrintfMethod · 0.80
VMethod · 0.80
ShutdownMethod · 0.65
NewDMapMethod · 0.65
ValueMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected