Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: race in outputting to the root io.Writer #18741

Closed
dsnet opened this issue Jan 22, 2017 · 1 comment
Closed

testing: race in outputting to the root io.Writer #18741

dsnet opened this issue Jan 22, 2017 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Jan 22, 2017

Using Go1.7.4.

Consider the following test:

func Test(t *testing.T) {
	var wg sync.WaitGroup
	defer wg.Wait()
	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			t.Run(fmt.Sprintf("LongLongLongLongName%d", i), func(t *testing.T) {})
		}(i)
	}
}

On some invocations, I see something like:

=== RUN   Test/LongLongLongLongName48
=== RUN   Test/LongLon=== RUN   Test/LongLongLongLongName50
gLongLongName49
=== RUN   Test/LongLongLongLongName51

In testing.go, we directly write "=== RUN %s\n" directly to the root's io.Writer (which is os.Stdout). Although it is safe to concurrently write to os.Stdout, the results can sometimes be non-sensical.

Instead, we should acquire the root's lock before writing.

@dsnet dsnet added this to the Go1.9 milestone Jan 22, 2017
@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 22, 2017
@gopherbot
Copy link

CL https://golang.org/cl/35556 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants