Commit d465ea57 authored by Roger Peppe's avatar Roger Peppe Committed by Rob Pike

netchan: export before import when testing.

Fixes some race conditions.

R=r
CC=golang-dev
https://golang.org/cl/2456041
parent 8a1b2e59
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment