diff options
| author | dvyukov <dvyukov@google.com> | 2015-10-28 17:49:17 +0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-11-24 17:00:43 +0000 |
| commit | 5526d95019f893412a4039187fc9f8eeca8f18c6 (patch) | |
| tree | 3c9e508da625cbd67cec814602d3fda0da35c679 /src/runtime/race/testdata | |
| parent | b597e1ed543a309926a3c3a94518a135844470ce (diff) | |
| download | go-5526d95019f893412a4039187fc9f8eeca8f18c6.tar.xz | |
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/16416
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/race/testdata')
| -rw-r--r-- | src/runtime/race/testdata/chan_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go index eabd81f40c..cddd9a6e78 100644 --- a/src/runtime/race/testdata/chan_test.go +++ b/src/runtime/race/testdata/chan_test.go @@ -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): + } +} |
