LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime_test | 5 package runtime_test |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | 8 "runtime" |
9 "sync" | 9 "sync" |
10 "sync/atomic" | 10 "sync/atomic" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g
ot %v/%v", chanCap, 0, chanCap, len(c), cap(c)) | 188 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g
ot %v/%v", chanCap, 0, chanCap, len(c), cap(c)) |
189 } | 189 } |
190 for i := 0; i < chanCap; i++ { | 190 for i := 0; i < chanCap; i++ { |
191 c <- i | 191 c <- i |
192 } | 192 } |
193 if len(c) != chanCap || cap(c) != chanCap { | 193 if len(c) != chanCap || cap(c) != chanCap { |
194 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g
ot %v/%v", chanCap, chanCap, chanCap, len(c), cap(c)) | 194 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g
ot %v/%v", chanCap, chanCap, chanCap, len(c), cap(c)) |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
| 198 } |
| 199 } |
| 200 |
| 201 func TestNonblockRecvRace(t *testing.T) { |
| 202 n := 10000 |
| 203 if testing.Short() { |
| 204 n = 100 |
| 205 } |
| 206 for i := 0; i < n; i++ { |
| 207 c := make(chan int, 1) |
| 208 c <- 1 |
| 209 go func() { |
| 210 select { |
| 211 case <-c: |
| 212 default: |
| 213 t.Fatal("chan is not ready") |
| 214 } |
| 215 }() |
| 216 close(c) |
| 217 <-c |
198 } | 218 } |
199 } | 219 } |
200 | 220 |
201 func TestSelfSelect(t *testing.T) { | 221 func TestSelfSelect(t *testing.T) { |
202 // Ensure that send/recv on the same chan in select | 222 // Ensure that send/recv on the same chan in select |
203 // does not crash nor deadlock. | 223 // does not crash nor deadlock. |
204 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2)) | 224 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2)) |
205 for _, chanCap := range []int{0, 10} { | 225 for _, chanCap := range []int{0, 10} { |
206 var wg sync.WaitGroup | 226 var wg sync.WaitGroup |
207 wg.Add(2) | 227 wg.Add(2) |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 func BenchmarkChanSem(b *testing.B) { | 782 func BenchmarkChanSem(b *testing.B) { |
763 type Empty struct{} | 783 type Empty struct{} |
764 myc := make(chan Empty, runtime.GOMAXPROCS(0)) | 784 myc := make(chan Empty, runtime.GOMAXPROCS(0)) |
765 b.RunParallel(func(pb *testing.PB) { | 785 b.RunParallel(func(pb *testing.PB) { |
766 for pb.Next() { | 786 for pb.Next() { |
767 myc <- Empty{} | 787 myc <- Empty{} |
768 <-myc | 788 <-myc |
769 } | 789 } |
770 }) | 790 }) |
771 } | 791 } |
LEFT | RIGHT |