Skip to content

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

Description

@dsnet

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions