Skip to content

Flaky test in TestS3WatcherTestSuite/TestStart due to race condition #313

@funkyshu

Description

@funkyshu

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

  1. Run the vfsevents test suite in CI: go test -v ./contrib/vfsevents/...
  2. The TestS3WatcherTestSuite/TestStart test occasionally fails
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions