MCPcopy Index your code
hub / github.com/dropbox/godropbox / TestLockKeyMultiple

Method TestLockKeyMultiple

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

Source from the content-addressed store, hash-verified

116}
117
118func (s *LockStoreSuite) TestLockKeyMultiple(c *C) {
119 storeRaw := New(LockStoreOptions{Granularity: PerKeyGranularity})
120 store := storeRaw.(*_LockStoreImp)
121 period := time.Second
122 wg := sync.WaitGroup{}
123 // rnd is not thread safe
124 rnd := rand.New(rand.NewSource(time.Now().Unix()))
125 lock := sync.Mutex{}
126 for i := 0; i < 1000; i++ {
127 i := i
128 key := "test-key-multiple-" + strconv.Itoa(i)
129 wg.Add(1)
130 go func() {
131 defer wg.Done()
132 // for rnd
133 store.Lock(key)
134 lock.Lock()
135 jitter := period/2 + time.Duration(rnd.Int63n(int64(period)))
136 lock.Unlock()
137 time.Sleep(jitter)
138 store.Unlock(key)
139 }()
140 }
141 wg.Wait()
142 c.Assert(len(store.perKeyLocks), Equals, 0)
143}
144
145func (s *LockStoreSuite) TestShardedLockKeySimple(c *C) {
146 key := "test-key-simple"

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