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

Data race when using EventuallyWithT() #1391

Closed
pmalek opened this issue May 30, 2023 · 0 comments · Fixed by #1395
Closed

Data race when using EventuallyWithT() #1391

pmalek opened this issue May 30, 2023 · 0 comments · Fixed by #1395
Labels
concurrency pkg-assert Change related to package testify/assert

Comments

@pmalek
Copy link

pmalek commented May 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency pkg-assert Change related to package testify/assert
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants