]> Cypherpunks repositories - gostls13.git/commitdiff
netchan: export before import when testing.
authorRoger Peppe <rogpeppe@gmail.com>
Tue, 12 Oct 2010 22:05:53 +0000 (15:05 -0700)
committerRob Pike <r@golang.org>
Tue, 12 Oct 2010 22:05:53 +0000 (15:05 -0700)
Fixes some race conditions.

R=r
CC=golang-dev
https://golang.org/cl/2456041

src/pkg/netchan/netchan_test.go

index 357d72c49ce04941b8086bd2873502803b2e9571..6efb8c5d74aa44e3bc112dd1776ce9c9ff14cca4 100644 (file)
@@ -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
 }