From b279c048e3b07f4cfc7e0605894350d72a10f8a6 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 26 Aug 2010 15:42:18 -0700 Subject: [PATCH] netchan: Fix race condition in test. Two tests start a goroutine which runs exportSend, and then the tests run importReceive. exportSend creates an export channel. importReceive asks to receive values on that channel. Because exportSend runs in a separate goroutine, it's possible for the export client to receive the request for values on the channel, from importReceive, before the goroutine actually creates the export channel. That causes an error: "export: no such channel: exportedSend". This patch avoids the race by creating the export channel before starting the goroutine. There does not seem to be a similar race condition in the tests which send data in the other direction. R=r CC=golang-dev https://golang.org/cl/2026045 --- src/pkg/netchan/netchan_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pkg/netchan/netchan_test.go b/src/pkg/netchan/netchan_test.go index 6b5c67c3ca..eb5a11ea44 100644 --- a/src/pkg/netchan/netchan_test.go +++ b/src/pkg/netchan/netchan_test.go @@ -15,10 +15,12 @@ func exportSend(exp *Exporter, n int, t *testing.T) { if err != nil { t.Fatal("exportSend:", err) } - for i := 0; i < n; i++ { - ch <- 23+i - } - close(ch) + go func() { + for i := 0; i < n; i++ { + ch <- 23+i + } + close(ch) + }() } func exportReceive(exp *Exporter, t *testing.T) { @@ -75,7 +77,7 @@ func TestExportSendImportReceive(t *testing.T) { if err != nil { t.Fatal("new importer:", err) } - go exportSend(exp, count, t) + exportSend(exp, count, t) importReceive(imp, t) } @@ -101,6 +103,6 @@ func TestClosingExportSendImportReceive(t *testing.T) { if err != nil { t.Fatal("new importer:", err) } - go exportSend(exp, closeCount, t) + exportSend(exp, closeCount, t) importReceive(imp, t) } -- 2.50.0