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

Function doTestParallelReaders

sync2/boundedrwlock_test.go:80–118  ·  view source on GitHub ↗
(gomaxprocs, numReaders int)

Source from the content-addressed store, hash-verified

78}
79
80func doTestParallelReaders(gomaxprocs, numReaders int) {
81 runtime.GOMAXPROCS(gomaxprocs)
82
83 var rwl *BoundedRWLock = NewBoundedRWLock(int(numReaders))
84 clocked := make(chan bool)
85 cunlock := make(chan bool)
86 cdone := make(chan bool)
87
88 reader := func() {
89 if err := rwl.RLock(100 * time.Millisecond); err != nil {
90 panic(fmt.Sprintf("contention??"))
91 }
92
93 clocked <- true
94 <-cunlock
95 rwl.RUnlock()
96 cdone <- true
97 }
98
99 // kick off parallel readers
100 for i := 0; i < numReaders; i++ {
101 go reader()
102 }
103
104 // wait for them to all acquire the rlock
105 for i := 0; i < numReaders; i++ {
106 <-clocked
107 }
108
109 // ask them to unlock
110 for i := 0; i < numReaders; i++ {
111 cunlock <- true
112 }
113
114 // wait for them to unlock
115 for i := 0; i < numReaders; i++ {
116 <-cdone
117 }
118}
119
120func (suite *BoundedRWLockSuite) TestParallelReaders(t *C) {
121 // restore the original value after we are done with the test

Callers 1

TestParallelReadersMethod · 0.85

Calls 4

RLockMethod · 0.95
RUnlockMethod · 0.95
NewBoundedRWLockFunction · 0.85
readerFunction · 0.85

Tested by

no test coverage detected