MCPcopy
hub / github.com/dropbox/godropbox / TestShardedLockKeyParallel

Method TestShardedLockKeyParallel

lockstore/store_test.go:176–202  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

174}
175
176func (s *LockStoreSuite) TestShardedLockKeyParallel(c *C) {
177 key := "test-key-parallel"
178 const count = 10
179 storeRaw := New(LockStoreOptions{Granularity: ShardedGranularity, LockCount: count})
180 store := storeRaw.(*_LockStoreImp)
181 period := time.Second
182 wg := sync.WaitGroup{}
183
184 // rnd is not thread-safe
185 lock := sync.Mutex{}
186 rnd := rand.New(rand.NewSource(time.Now().Unix()))
187 // this test will take approximately 10 sec
188 for i := 0; i < 10; i++ {
189 wg.Add(1)
190 go func() {
191 defer wg.Done()
192 store.Lock(key)
193 lock.Lock()
194 jitter := period/2 + time.Duration(rnd.Int63n(int64(period)))
195 lock.Unlock()
196 time.Sleep(jitter)
197 store.Unlock(key)
198 }()
199 }
200
201 wg.Wait()
202}
203
204func (s *LockStoreSuite) TestShardedLockKeyMultiple(c *C) {
205 const count = 10

Callers

nothing calls this directly

Calls 9

DurationMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
NowMethod · 0.65
AddMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65
SleepMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected