Skip to content

test: fix fake informer removal race - #742

Open
outsider987 wants to merge 1 commit into
rancher:mainfrom
outsider987:fix/462-test-informer-race
Open

outsider987 wants to merge 1 commit into
rancher:mainfrom
outsider987:fix/462-test-informer-race

Conversation

@outsider987

Copy link
Copy Markdown

Summary

Fixes #462.

Synchronize the test fakeInformer's shared slices, signal completion after removal, and fail explicitly on timeout. Callbacks and channel waits run outside the mutex. Production code and the existing event-count assertions are unchanged.

Verification

Local Linux/amd64, Go 1.26.0; baseline c4b075131e36a1c89b39c89baa7615396d009992.

Check Result
Original test, -race -count=100 FAIL: data race and handler-removal assertion
Fixed test, same command PASS
Fixed test, -race -count=100 -cpu=1,2,4 PASS (300 executions)
Entire pkg/relatedresource package, -race PASS
Full repository, go test -mod=readonly ./... PASS
Mutation: signal completion but retain the handler FAIL: existing handler-removal assertion
Mutation: skip removal and its completion signal FAIL: explicit timeout after 1 second
go test -mod=readonly -race ./pkg/relatedresource -run '^Test_addResourceEventHandler$' -count=100
go test -mod=readonly -race ./pkg/relatedresource -run '^Test_addResourceEventHandler$' -count=100 -cpu=1,2,4
go test -mod=readonly -race ./pkg/relatedresource
go test -mod=readonly ./...

Mutations were tested through temporary Go overlays, not included in this change. This verifies the test helper's synchronization, not a production-cluster failure.

Before / after: synchronization
flowchart LR
  subgraph Before
    B1[Signal completion] --> B2[Remove handler]
    B1 --> B3[Test resumes]
    B2 -.->|Unsynchronized shared slices| B3
  end
  subgraph After
    A1[Lock shared state] --> A2[Remove handler]
    A2 --> A3[Signal completion and unlock]
    A3 --> A4[Test checks subsequent events]
  end
Loading

Before the fix, the waiter's slice lookup can also race with removal, even before it receives the completion signal. The fix protects that lookup and captures the channel under the same mutex.

Signed-off-by: Victor Chang <t7902195204@gmail.com>
@outsider987
outsider987 requested a review from a team as a code owner September 15, 2026 07:26
@outsider987

Copy link
Copy Markdown
Author

Could a maintainer approve the pending CI run and review this test-only fix? Local race checks and the full test suite pass. Thanks!

@brandond

Copy link
Copy Markdown
Member

Thanks for the fix... can I ask why you picked this up? Wrangler doesn't see a lot of use outside the Rancher ecosystem and the issue was created by a maintainer mostly just to track a flake, so I'm curious what brought you here.

@outsider987

outsider987 commented Sep 16, 2026 via email

Copy link
Copy Markdown
Author

@outsider987

Copy link
Copy Markdown
Author

if that is bad I will cancel this fixed, sry

@brandond

Copy link
Copy Markdown
Member

no, no problem - just curious.

@outsider987

Copy link
Copy Markdown
Author

let's go~~~

@brandond

Copy link
Copy Markdown
Member

lgm. someone from @rancher/rancher-squad-frameworks needs to approve as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition in changeset_test.go:Test_addResourceEventHandler

2 participants