Skip to content

Data race when using EventuallyWithT() #1391

@pmalek

Description

@pmalek

When using EventuallyWithT() from 1.8.3 like so:

package main

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestEventuallyWithT(t *testing.T) {
	assert.EventuallyWithT(t, func(c *assert.CollectT) {
		assert.NoError(c, assert.AnError)
	}, time.Millisecond, time.Nanosecond)
}

the following data race is triggered:

=== RUN   TestEventuallyWithT
==================
WARNING: DATA RACE
Write at 0x00c0000b42a0 by goroutine 26:
  github.com/stretchr/testify/assert.(*CollectT).Errorf()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:1869 +0x110
  github.com/stretchr/testify/assert.Fail()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:333 +0x358
  github.com/stretchr/testify/assert.NoError()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:1495 +0xe0
  eventuallwitht.TestEventuallyWithT.func1()
      eventuallwitht/main_test.go:12 +0x58
  github.com/stretchr/testify/assert.EventuallyWithT.func1()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:1933 +0x44

Previous read at 0x00c0000b42a0 by goroutine 6:
  github.com/stretchr/testify/assert.(*CollectT).Copy()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:1887 +0x58
  github.com/stretchr/testify/assert.EventuallyWithT()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:1927 +0x354
  eventuallwitht.TestEventuallyWithT()
      eventuallwitht/main_test.go:11 +0x50
  testing.tRunner()
      testing/testing.go:1576 +0x188
  testing.(*T).Run.func1()
      testing/testing.go:1629 +0x40

Goroutine 26 (running) created at:
  github.com/stretchr/testify/assert.EventuallyWithT()
      github.com/stretchr/testify@v1.8.3/assert/assertions.go:1932 +0x310
  eventuallwitht.TestEventuallyWithT()
      eventuallwitht/main_test.go:11 +0x50
  testing.tRunner()
      testing/testing.go:1576 +0x188
  testing.(*T).Run.func1()
      testing/testing.go:1629 +0x40

Goroutine 6 (running) created at:
  testing.(*T).Run()
      testing/testing.go:1629 +0x5e4
  testing.runTests.func1()
      testing/testing.go:2036 +0x80
  testing.tRunner()
      testing/testing.go:1576 +0x188
  testing.runTests()
      testing/testing.go:2034 +0x700
  testing.(*M).Run()
      testing/testing.go:1906 +0x950
  main.main()
      _testmain.go:47 +0x300
==================

It seems that those .errors accesses should be guarded with a lock.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions