Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: common/sync/mutexpool/pool_test.go

Issue 2640323003: common/sync/mutexpool: Add mutexpool. (Closed)
Patch Set: Comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/sync/mutexpool/pool.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package mutexpool
6
7 import (
8 "sync"
9 "testing"
10
11 . "github.com/smartystreets/goconvey/convey"
12 )
13
14 func TestPool(t *testing.T) {
15 t.Parallel()
16
17 Convey(`A mutex pool`, t, func() {
18 var pool P
19
20 Convey(`Can handle multiple concurrent Mutex accesses, and will clean up when finished.`, func() {
21 const total = 1000
22 var value int
23 var wg sync.WaitGroup
24
25 wg.Add(total)
26 for i := 0; i < total; i++ {
27 go func() {
28 pool.WithMutex("foo", func() {
29 value++
30 })
31 wg.Done()
32 }()
33 }
34
35 wg.Wait()
36 So(value, ShouldEqual, total)
37 So(pool.mutexes, ShouldHaveLength, 0)
38 })
39
40 Convey(`Can handle multiple keys.`, func() {
41 const total = 100
42 var recLock func(int)
43 recLock = func(v int) {
44 if v < total {
45 pool.WithMutex(v, func() {
46 So(pool.mutexes, ShouldHaveLengt h, v+1)
47 recLock(v + 1)
48 })
49 }
50 }
51 recLock(0)
52 So(pool.mutexes, ShouldHaveLength, 0)
53 })
54 })
55 }
OLDNEW
« no previous file with comments | « common/sync/mutexpool/pool.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698