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

Function TestDMap_Atomic_Decr

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

Source from the content-addressed store, hash-verified

102}
103
104func TestDMap_Atomic_Decr(t *testing.T) {
105 cluster := testcluster.New(NewService)
106 s := cluster.AddMember(nil).(*Service)
107 defer cluster.Shutdown()
108
109 var wg sync.WaitGroup
110 var start chan struct{}
111 key := "decr"
112
113 ctx := context.Background()
114
115 decr := func(dm *DMap) {
116 <-start
117 defer wg.Done()
118
119 _, err := dm.Decr(ctx, key, 1)
120 if err != nil {
121 s.log.V(2).Printf("[ERROR] Failed to call Decr: %v", err)
122 return
123 }
124 }
125
126 dm, err := s.NewDMap("atomic_test")
127 require.NoError(t, err)
128
129 start = make(chan struct{})
130 for i := 0; i < 100; i++ {
131 wg.Add(1)
132 go decr(dm)
133 }
134 close(start)
135 wg.Wait()
136
137 res, err := dm.Get(context.Background(), key)
138 require.NoError(t, err)
139
140 var value int
141 err = resp.Scan(res.Value(), &value)
142 require.NoError(t, err)
143 require.Equal(t, -100, value)
144}
145
146func TestDMap_Atomic_GetPut(t *testing.T) {
147 cluster := testcluster.New(NewService)

Callers

nothing calls this directly

Calls 11

DecrMethod · 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