Skip to content

fix: resolve TestAPI/Error/DuringInjection flake #19407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions agent/agentcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2096,9 +2096,6 @@ func TestAPI(t *testing.T) {
}
)

coderBin, err := os.Executable()
require.NoError(t, err)
Comment on lines -2099 to -2100
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this might sometimes be a symlink which we aren't resolving which causes a problem in the tests on nightly gauntlet. Instead of resolving this symlink, I've just removed this and replaced the mock expectation with gomock.Any() as we don't really care about this for this test.


// Mock the `List` function to always return the test container.
mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Containers: []codersdk.WorkspaceAgentContainer{testContainer},
Expand Down Expand Up @@ -2139,7 +2136,7 @@ func TestAPI(t *testing.T) {
require.Equal(t, http.StatusOK, rec.Code)

var response codersdk.WorkspaceAgentListContainersResponse
err = json.NewDecoder(rec.Body).Decode(&response)
err := json.NewDecoder(rec.Body).Decode(&response)
require.NoError(t, err)

// Then: We expect that there will be an error associated with the devcontainer.
Expand All @@ -2149,16 +2146,16 @@ func TestAPI(t *testing.T) {
gomock.InOrder(
mCCLI.EXPECT().DetectArchitecture(gomock.Any(), testContainer.ID).Return(runtime.GOARCH, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, gomock.Any(), "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

// Given: We allow creation to succeed.
testutil.RequireSend(ctx, t, fSAC.createErrC, nil)

_, aw := mClock.AdvanceNext()
aw.MustWait(ctx)
err = api.RefreshContainers(ctx)
require.NoError(t, err)
Comment on lines +2157 to +2158
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drive by fix: whilst trying to recreate this flake, i got this to fail because the clock would skip a turn for some reason, so instead we just invoke RefreshContainers directly.


req = httptest.NewRequest(http.MethodGet, "/", nil)
rec = httptest.NewRecorder()
Expand Down
Loading