1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
14
func TestNoRaceWaitGroup(t *testing.T) {
18
for i := 0; i < n; i++ {
29
func TestRaceWaitGroup(t *testing.T) {
33
for i := 0; i < n; i++ {
44
func TestNoRaceWaitGroup2(t *testing.T) {
56
// incrementing counter in Add and locking wg's mutex
57
func TestRaceWaitGroupAsMutex(t *testing.T) {
60
c := make(chan bool, 2)
63
time.Sleep(100 * time.Millisecond)
71
time.Sleep(100 * time.Millisecond)
81
// Incorrect usage: Add is too late.
82
func TestRaceWaitGroupWrongWait(t *testing.T) {
83
c := make(chan bool, 2)
105
// A common WaitGroup misuse that can potentially be caught be the race detector.
106
// For this simple case we must emulate Add() as read on &wg and Wait() as write on &wg.
107
// However it will have false positives if there are several concurrent Wait() calls.
108
func TestRaceFailingWaitGroupWrongAdd(t *testing.T) {
109
c := make(chan bool, 2)
110
var wg sync.WaitGroup
126
func TestNoRaceWaitGroupMultipleWait(t *testing.T) {
127
c := make(chan bool, 2)
128
var wg sync.WaitGroup
142
func TestNoRaceWaitGroupMultipleWait2(t *testing.T) {
143
c := make(chan bool, 2)
144
var wg sync.WaitGroup
161
// Correct usage but still a race
162
func TestRaceWaitGroup2(t *testing.T) {
164
var wg sync.WaitGroup
177
func TestNoRaceWaitGroupPanicRecover(t *testing.T) {
179
var wg sync.WaitGroup
182
if err != "sync: negative WaitGroup counter" {
183
t.Fatalf("Unexpected panic: %#v", err)
191
// TODO: this is actually a panic-synchronization test, not a
192
// WaitGroup test. Move it to another *_test file
193
// Is it possible to get a race by synchronization via panic?
194
func TestNoRaceWaitGroupPanicRecover2(t *testing.T) {
196
var wg sync.WaitGroup
197
ch := make(chan bool, 1)
198
var f func() = func() {
205
if err != "sync: negative WaitGroup counter" {
216
func TestNoRaceWaitGroupTransitive(t *testing.T) {
218
var wg sync.WaitGroup