- Notifications
You must be signed in to change notification settings - Fork1k
fix(agent/agentcontainers): reset error at start of rebuild#18686
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsagent/agentcontainers/api.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
31 changes: 23 additions & 8 deletionsagent/agentcontainers/api_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -69,7 +69,7 @@ func (f *fakeContainerCLI) ExecAs(ctx context.Context, name, user string, args . | ||
type fakeDevcontainerCLI struct { | ||
upID string | ||
upErr error | ||
upErrC chanfunc()error // If set, send to return err, close to return upErr. | ||
execErr error | ||
execErrC chan func(cmd string, args ...string) error // If set, send fn to return err, nil or close to return execErr. | ||
readConfig agentcontainers.DevcontainerConfig | ||
@@ -82,9 +82,9 @@ func (f *fakeDevcontainerCLI) Up(ctx context.Context, _, _ string, _ ...agentcon | ||
select { | ||
case <-ctx.Done(): | ||
return "", ctx.Err() | ||
casefn, ok := <-f.upErrC: | ||
if ok { | ||
return f.upID,fn() | ||
} | ||
} | ||
} | ||
@@ -613,7 +613,7 @@ func TestAPI(t *testing.T) { | ||
nowRecreateErrorTrap := mClock.Trap().Now("recreate", "errorTimes") | ||
nowRecreateSuccessTrap := mClock.Trap().Now("recreate", "successTimes") | ||
tt.devcontainerCLI.upErrC = make(chanfunc()error) | ||
// Setup router with the handler under test. | ||
r := chi.NewRouter() | ||
@@ -1665,7 +1665,7 @@ func TestAPI(t *testing.T) { | ||
mClock = quartz.NewMock(t) | ||
fCCLI = &fakeContainerCLI{arch: "<none>"} | ||
fDCCLI = &fakeDevcontainerCLI{ | ||
upErrC: make(chanfunc()error, 1), | ||
} | ||
fSAC = &fakeSubAgentClient{ | ||
logger: logger.Named("fakeSubAgentClient"), | ||
@@ -1717,7 +1717,7 @@ func TestAPI(t *testing.T) { | ||
// Given: We simulate an error running `devcontainer up` | ||
simulatedError := xerrors.New("simulated error") | ||
testutil.RequireSend(ctx, t, fDCCLI.upErrC,func() error { returnsimulatedError }) | ||
nowRecreateErrorTrap.MustWait(ctx).MustRelease(ctx) | ||
nowRecreateErrorTrap.Close() | ||
@@ -1742,7 +1742,22 @@ func TestAPI(t *testing.T) { | ||
require.Equal(t, http.StatusAccepted, rec.Code) | ||
// Given: We allow `devcontainer up` to succeed. | ||
testutil.RequireSend(ctx, t, fDCCLI.upErrC, func() error { | ||
req = httptest.NewRequest(http.MethodGet, "/", nil) | ||
rec = httptest.NewRecorder() | ||
r.ServeHTTP(rec, req) | ||
require.Equal(t, http.StatusOK, rec.Code) | ||
response = codersdk.WorkspaceAgentListContainersResponse{} | ||
err = json.NewDecoder(rec.Body).Decode(&response) | ||
require.NoError(t, err) | ||
// Then: We make sure that the error has been cleared before running up. | ||
require.Len(t, response.Devcontainers, 1) | ||
require.Equal(t, "", response.Devcontainers[0].Error) | ||
return nil | ||
}) | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
nowRecreateSuccessTrap.MustWait(ctx).MustRelease(ctx) | ||
nowRecreateSuccessTrap.Close() | ||
@@ -1756,7 +1771,7 @@ func TestAPI(t *testing.T) { | ||
err = json.NewDecoder(rec.Body).Decode(&response) | ||
require.NoError(t, err) | ||
// Then: Wealsoexpect no errorafter running up.. | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
require.Len(t, response.Devcontainers, 1) | ||
require.Equal(t, "", response.Devcontainers[0].Error) | ||
}) | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.