1
0
mirror of https://github.com/golang/go synced 2024-11-20 04:54:44 -07:00

netchan: export before import when testing.

Fixes some race conditions.

R=r
CC=golang-dev
https://golang.org/cl/2456041
This commit is contained in:
Roger Peppe 2010-10-12 15:05:53 -07:00 committed by Rob Pike
parent 8a1b2e59ef
commit d465ea5724

View 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
}