From d76f28fc39400b918f7951b7e7f12b0dc4a98b0a Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 1 Apr 2013 11:49:24 -0700 Subject: [PATCH] runtime: add concurrent map read test Currently crashes, so disabled. Update #5179 R=golang-dev, khr CC=golang-dev https://golang.org/cl/8222044 --- src/pkg/runtime/map_test.go | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/pkg/runtime/map_test.go b/src/pkg/runtime/map_test.go index 1bf6b60d83..cc8863b2ee 100644 --- a/src/pkg/runtime/map_test.go +++ b/src/pkg/runtime/map_test.go @@ -7,8 +7,10 @@ package runtime_test import ( "fmt" "math" + "os" "runtime" "sort" + "sync" "testing" ) @@ -231,6 +233,43 @@ func TestIterGrowWithGC(t *testing.T) { } } +func TestConcurrentReadsAfterGrowth(t *testing.T) { + // TODO(khr): fix and enable this test. + t.Skip("Known currently broken; golang.org/issue/5179") + + if os.Getenv("GOMAXPROCS") == "" { + defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(16)) + } + numLoop := 10 + numGrowStep := 250 + numReader := 16 + if testing.Short() { + numLoop, numGrowStep = 2, 500 + } + for i := 0; i < numLoop; i++ { + m := make(map[int]int, 0) + for gs := 0; gs < numGrowStep; gs++ { + m[gs] = gs + var wg sync.WaitGroup + wg.Add(numReader * 2) + for nr := 0; nr < numReader; nr++ { + go func() { + defer wg.Done() + for _ = range m { + } + }() + go func() { + defer wg.Done() + for key := 0; key < gs; key++ { + _ = m[key] + } + }() + } + wg.Wait() + } + } +} + func TestBigItems(t *testing.T) { var key [256]string for i := 0; i < 256; i++ { -- 2.50.0