Skip to content

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Dec 2, 2025

The test had two issues:

  1. Data race in fakeSubAgentClient: The test helper was accessed
    concurrently from the API's updater loop and from API.Close()
    without synchronization. Added a mutex to protect shared map
    and slice access.

  2. Missing clock advance: After nowRecreateSuccessTrap fires,
    CreateDevcontainer still calls RefreshContainers which needs
    to complete before the test checks the response. Added clock
    advance to match the pattern used in other similar tests.

Also changed assert.NotNil to require.NotNil to prevent nil pointer
dereference if the assertion fails.

Fixes coder/internal#1169

…ntainerID test

The test had two issues:

1. Data race in fakeSubAgentClient: The test helper was accessed
   concurrently from the API's updater loop and from API.Close()
   without synchronization. Added a mutex to protect shared map
   and slice access.

2. Missing clock advance: After nowRecreateSuccessTrap fires,
   CreateDevcontainer still calls RefreshContainers which needs
   to complete before the test checks the response. Added clock
   advance to match the pattern used in other similar tests.

Also changed assert.NotNil to require.NotNil to prevent nil pointer
dereference if the assertion fails.

Fixes coder/internal#1169
@mafredri mafredri requested review from SasSwart and mtojek December 2, 2025 14:31
@mafredri mafredri changed the title fix(agent/agentcontainers): fix data race and flake in DuringUpWithContainerID test test(agent/agentcontainers): fix data race and flake in DuringUpWithContainerID test Dec 2, 2025
@mafredri mafredri enabled auto-merge (squash) December 2, 2025 15:14
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stamp 👍

@mafredri mafredri merged commit 929db24 into main Dec 2, 2025
30 checks passed
@mafredri mafredri deleted the mafredri/test-fix-agentcontaienrs-test-race branch December 2, 2025 15:18
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: Data race in agent/agentcontainers - TestAPI/Error/DuringUpWithContainerID

3 participants