Skip to content

Data race when using EventuallyWithT() #1391

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.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions