Skip to content

Commit d76f28f

Browse files
committed
runtime: add concurrent map read test
Currently crashes, so disabled. Update #5179 R=golang-dev, khr CC=golang-dev https://golang.org/cl/8222044
1 parent 79a0c17 commit d76f28f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/pkg/runtime/map_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ package runtime_test
77
import (
88
"fmt"
99
"math"
10+
"os"
1011
"runtime"
1112
"sort"
13+
"sync"
1214
"testing"
1315
)
1416

@@ -231,6 +233,43 @@ func TestIterGrowWithGC(t *testing.T) {
231233
}
232234
}
233235

236+
func TestConcurrentReadsAfterGrowth(t *testing.T) {
237+
// TODO(khr): fix and enable this test.
238+
t.Skip("Known currently broken; golang.org/issue/5179")
239+
240+
if os.Getenv("GOMAXPROCS") == "" {
241+
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(16))
242+
}
243+
numLoop := 10
244+
numGrowStep := 250
245+
numReader := 16
246+
if testing.Short() {
247+
numLoop, numGrowStep = 2, 500
248+
}
249+
for i := 0; i < numLoop; i++ {
250+
m := make(map[int]int, 0)
251+
for gs := 0; gs < numGrowStep; gs++ {
252+
m[gs] = gs
253+
var wg sync.WaitGroup
254+
wg.Add(numReader * 2)
255+
for nr := 0; nr < numReader; nr++ {
256+
go func() {
257+
defer wg.Done()
258+
for _ = range m {
259+
}
260+
}()
261+
go func() {
262+
defer wg.Done()
263+
for key := 0; key < gs; key++ {
264+
_ = m[key]
265+
}
266+
}()
267+
}
268+
wg.Wait()
269+
}
270+
}
271+
}
272+
234273
func TestBigItems(t *testing.T) {
235274
var key [256]string
236275
for i := 0; i < 256; i++ {

0 commit comments

Comments
 (0)