| 174 | } |
| 175 | |
| 176 | func (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 | |
| 204 | func (s *LockStoreSuite) TestShardedLockKeyMultiple(c *C) { |
| 205 | const count = 10 |