Commit b279c048 authored by Ian Lance Taylor's avatar Ian Lance Taylor

netchan: Fix race condition in test.

Two tests start a goroutine which runs exportSend, and then
the tests run importReceive.  exportSend creates an export
channel.  importReceive asks to receive values on that
channel.  Because exportSend runs in a separate goroutine,
it's possible for the export client to receive the request for
values on the channel, from importReceive, before the
goroutine actually creates the export channel.  That causes an
error: "export: no such channel: exportedSend".  This patch
avoids the race by creating the export channel before starting
the goroutine.

There does not seem to be a similar race condition in the
tests which send data in the other direction.

R=r
CC=golang-dev
https://golang.org/cl/2026045
parent 3b226f98
......@@ -15,10 +15,12 @@ func exportSend(exp *Exporter, n int, t *testing.T) {
if err != nil {
t.Fatal("exportSend:", err)
}
for i := 0; i < n; i++ {
ch <- 23+i
}
close(ch)
go func() {
for i := 0; i < n; i++ {
ch <- 23+i
}
close(ch)
}()
}
func exportReceive(exp *Exporter, t *testing.T) {
......@@ -75,7 +77,7 @@ func TestExportSendImportReceive(t *testing.T) {
if err != nil {
t.Fatal("new importer:", err)
}
go exportSend(exp, count, t)
exportSend(exp, count, t)
importReceive(imp, t)
}
......@@ -101,6 +103,6 @@ func TestClosingExportSendImportReceive(t *testing.T) {
if err != nil {
t.Fatal("new importer:", err)
}
go exportSend(exp, closeCount, t)
exportSend(exp, closeCount, t)
importReceive(imp, t)
}
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