From d465ea572418c98dea54cfdfe16e170ab534ba0b Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 12 Oct 2010 15:05:53 -0700 Subject: [PATCH] netchan: export before import when testing. Fixes some race conditions. R=r CC=golang-dev https://golang.org/cl/2456041 --- src/pkg/netchan/netchan_test.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/pkg/netchan/netchan_test.go b/src/pkg/netchan/netchan_test.go index 357d72c49c..6efb8c5d74 100644 --- a/src/pkg/netchan/netchan_test.go +++ b/src/pkg/netchan/netchan_test.go @@ -29,9 +29,10 @@ func exportSend(exp *Exporter, n int, t *testing.T) { }() } -func exportReceive(exp *Exporter, t *testing.T) { +func exportReceive(exp *Exporter, t *testing.T, expDone chan bool) { ch := make(chan int) err := exp.Export("exportedRecv", ch, Recv) + expDone <- true if err != nil { t.Fatal("exportReceive:", err) } @@ -108,8 +109,15 @@ func TestExportReceiveImportSend(t *testing.T) { if err != nil { t.Fatal("new importer:", err) } + expDone := make(chan bool) + done := make(chan bool) + go func() { + exportReceive(exp, t, expDone) + done <- true + }() + <-expDone importSend(imp, count, t) - exportReceive(exp, t) + <-done } func TestClosingExportSendImportReceive(t *testing.T) { @@ -134,8 +142,15 @@ func TestClosingImportSendExportReceive(t *testing.T) { if err != nil { t.Fatal("new importer:", err) } + expDone := make(chan bool) + done := make(chan bool) + go func() { + exportReceive(exp, t, expDone) + done <- true + }() + <-expDone importSend(imp, closeCount, t) - exportReceive(exp, t) + <-done } func TestErrorForIllegalChannel(t *testing.T) { @@ -188,7 +203,11 @@ func TestExportDrain(t *testing.T) { t.Fatal("new importer:", err) } done := make(chan bool) - go exportSend(exp, closeCount, t) + go func() { + exportSend(exp, closeCount, t) + done <- true + }() + <-done go importReceive(imp, t, done) exp.Drain(0) <-done @@ -205,8 +224,8 @@ func TestExportSync(t *testing.T) { t.Fatal("new importer:", err) } done := make(chan bool) - go importReceive(imp, t, done) exportSend(exp, closeCount, t) + go importReceive(imp, t, done) exp.Sync(0) <-done } -- 2.50.0