testify: race condition on master in mock
Upgraded to master and tests that previously ran without issues now fail the race detector:
$ go test ./model/modelhelpers/ -race -run TestUpdateRefreshScheduleTimerSuccess
==================
WARNING: DATA RACE
Read at 0x00c4203a34e8 by goroutine 21:
reflect.typedmemmove()
/usr/local/Cellar/go/1.10.2/libexec/src/runtime/mbarrier.go:265 +0x0
reflect.packEface()
/usr/local/Cellar/go/1.10.2/libexec/src/reflect/value.go:119 +0x101
reflect.valueInterface()
/usr/local/Cellar/go/1.10.2/libexec/src/reflect/value.go:978 +0x16a
reflect.Value.Interface()
/usr/local/Cellar/go/1.10.2/libexec/src/reflect/value.go:948 +0x51
fmt.(*pp).printValue()
/usr/local/Cellar/go/1.10.2/libexec/src/fmt/print.go:699 +0x3700
fmt.(*pp).printValue()
/usr/local/Cellar/go/1.10.2/libexec/src/fmt/print.go:853 +0x2550
fmt.(*pp).printArg()
/usr/local/Cellar/go/1.10.2/libexec/src/fmt/print.go:689 +0x192
fmt.(*pp).doPrintf()
/usr/local/Cellar/go/1.10.2/libexec/src/fmt/print.go:1099 +0x912
fmt.Sprintf()
/usr/local/Cellar/go/1.10.2/libexec/src/fmt/print.go:203 +0x73
some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock.Arguments.Diff()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock/mock.go:678 +0x1416
some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock.(*Mock).findExpectedCall()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock/mock.go:267 +0x175
some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock.(*Mock).MethodCalled()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock/mock.go:343 +0xb3
some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock.(*Mock).Called()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock/mock.go:333 +0x18a
some.company.com/some/go-repo/mocks.(*ProvidesTimers).Remove()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/mocks/provides_timers.go:40 +0x2a1
Previous write at 0x00c4203a34e8 by goroutine 20:
sync/atomic.CompareAndSwapInt32()
/usr/local/Cellar/go/1.10.2/libexec/src/runtime/race_amd64.s:293 +0xb
sync.(*Mutex).Lock()
/usr/local/Cellar/go/1.10.2/libexec/src/sync/mutex.go:74 +0x4d
some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock.(*Mock).AssertCalled()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/vendor/github.com/stretchr/testify/mock/mock.go:489 +0xc8
some.company.com/some/go-repo/model/modelhelpers.TestUpdateRefreshScheduleTimerSuccess()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/model/modelhelpers/helpers_test.go:267 +0xafe
testing.tRunner()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:777 +0x16d
Goroutine 21 (running) created at:
some.company.com/some/go-repo/model/modelhelpers.removeTimerAsync()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/model/modelhelpers/helpers.go:94 +0x10f
some.company.com/some/go-repo/model/modelhelpers.UpdateRefreshScheduleTimer()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/model/modelhelpers/helpers.go:152 +0x2c2
some.company.com/some/go-repo/model/modelhelpers.TestUpdateRefreshScheduleTimerSuccess()
/Users/andrewdeandrade/go/src/some.company.com/some/go-repo/model/modelhelpers/helpers_test.go:241 +0x5e0
testing.tRunner()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:777 +0x16d
Goroutine 20 (running) created at:
testing.(*T).Run()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:824 +0x564
testing.runTests.func1()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:1063 +0xa4
testing.tRunner()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:777 +0x16d
testing.runTests()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:1061 +0x4e1
testing.(*M).Run()
/usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:978 +0x2cd
main.main()
_testmain.go:52 +0x22a
Has anyone else encountered this?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 24 (5 by maintainers)
Commits related to this issue
- Fix #625 Diff race condition — committed to gz-c/testify by gz-c 6 years ago
- Add String method to Mock to fix #625 — committed to neilisaac/testify by deleted user 6 years ago
I’m still seeing what looks to be a related error on master @ 6241f9ab994219cafb009b160a20acf4a62063aa
In my case, the particular mock that seems to be problematic is
I’m also on v.1.6.1, and see the same race condition appear every now and then.
Some of our arguments to a mocked function are structs containing a sync.Mutex. The
Called()function deeply inspects those, which causes a race condition with the Mutex.Lock() function.We already changed our
mock.On(...)-calls to usemock.AnythingOfType(...)for those structs, with the reasoning that if the type matches, there should be no need to do that deep inspection (with reflection) of all struct members at all. But unfortunately this makes no difference:mock.Arguments.Diffis still being called bymock.Called, causing the race condition.I think the problem is more evident when mocking functions that receive a
contextI’m still seeing the data race:
Using: