Commit 5526d950 authored by dvyukov's avatar dvyukov Committed by Russ Cox

runtime/race: add tests for channels

These tests were failing on one of the versions of cl/9345
("runtime: simplify buffered channels").

Change-Id: I920ffcd28de428bcb7c2d5a300068644260e1017
Reviewed-on: https://go-review.googlesource.com/16416Reviewed-by: 's avatarKeith Randall <khr@golang.org>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b597e1ed
......@@ -657,3 +657,42 @@ func TestNoRaceChanWaitGroup(t *testing.T) {
_ = data[i]
}
}
// Test that sender synchronizes with receiver even if the sender was blocked.
func TestNoRaceBlockedSendSync(t *testing.T) {
c := make(chan *int, 1)
c <- nil
go func() {
i := 42
c <- &i
}()
// Give the sender time to actually block.
// This sleep is completely optional: race report must not be printed
// regardless of whether the sender actually blocks or not.
// It cannot lead to flakiness.
time.Sleep(10 * time.Millisecond)
<-c
p := <-c
if *p != 42 {
t.Fatal()
}
}
// The same as TestNoRaceBlockedSendSync above, but sender unblock happens in a select.
func TestNoRaceBlockedSelectSendSync(t *testing.T) {
c := make(chan *int, 1)
c <- nil
go func() {
i := 42
c <- &i
}()
time.Sleep(10 * time.Millisecond)
<-c
select {
case p := <-c:
if *p != 42 {
t.Fatal()
}
case <-make(chan int):
}
}
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