diff options
author | Roger Peppe <rogpeppe@gmail.com> | 2010-10-12 15:05:53 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2010-10-12 15:05:53 -0700 |
commit | d465ea572418c98dea54cfdfe16e170ab534ba0b (patch) | |
tree | c3e21488e3d4be75bdbaf0a285b267857d7ce635 | |
parent | 8a1b2e59ef553228a60d6799a2e001761e1e8ca8 (diff) | |
download | go-d465ea572418c98dea54cfdfe16e170ab534ba0b.tar.gz go-d465ea572418c98dea54cfdfe16e170ab534ba0b.zip |
netchan: export before import when testing.
Fixes some race conditions.
R=r
CC=golang-dev
https://golang.org/cl/2456041
-rw-r--r-- | src/pkg/netchan/netchan_test.go | 29 |
1 files 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 } |