Describe the bug
The TestS3WatcherTestSuite/TestStart test in contrib/vfsevents intermittently fails with an unexpected mock method call error. The test passes on retry, indicating a race condition in the test setup.
To Reproduce
- Run the vfsevents test suite in CI:
go test -v ./contrib/vfsevents/...
- The
TestS3WatcherTestSuite/TestStart test occasionally fails
- Re-running the same test succeeds
Expected behavior
The test should pass consistently without flakiness.
Error Output
--- FAIL: TestS3WatcherTestSuite (0.26s)
--- FAIL: TestS3WatcherTestSuite/TestStart (0.00s)
mock.go:361:
assert: mock: I don't know what to return because the method call was unexpected.
Either do Mock.On("ReceiveMessage").Return(...) first, or remove the ReceiveMessage() call.
This method was unexpected:
ReceiveMessage(*context.cancelCtx,*sqs.ReceiveMessageInput)
0: &context.cancelCtx{...err:atomic.Value{v:(*errors.errorString)...}}
1: &sqs.ReceiveMessageInput{QueueUrl:(*string)(0x14000909c70), MaxNumberOfMessages:10, ...}
Additional context
The error shows ReceiveMessage was called with a canceled context, suggesting a race between:
- The watcher goroutine making a
ReceiveMessage call after Start() is invoked
- The test canceling/stopping the watcher before mock expectations are fully exercised
Potential fixes:
- Add mock expectation for
ReceiveMessage that handles the post-cancellation call
- Ensure context cancellation is checked before calling SQS methods
- Use
mock.Anything for context matching to handle different context states
- Add synchronization between test setup and watcher goroutine startup
Describe the bug
The
TestS3WatcherTestSuite/TestStarttest incontrib/vfseventsintermittently fails with an unexpected mock method call error. The test passes on retry, indicating a race condition in the test setup.To Reproduce
go test -v ./contrib/vfsevents/...TestS3WatcherTestSuite/TestStarttest occasionally failsExpected behavior
The test should pass consistently without flakiness.
Error Output
Additional context
The error shows
ReceiveMessagewas called with a canceled context, suggesting a race between:ReceiveMessagecall afterStart()is invokedPotential fixes:
ReceiveMessagethat handles the post-cancellation callmock.Anythingfor context matching to handle different context states