Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ func (api *API) watchWorkspaceAgentMetadata(rw http.ResponseWriter, r *http.Requ
Keys: payload.Keys,
})
if err != nil {
if !errors.Is(err, context.Canceled) {
if !database.IsQueryCanceledError(err) {
log.Error(ctx, "failed to get metadata", slog.Error(err))
_ = sseSendEvent(ctx, codersdk.ServerSentEvent{
Type: codersdk.ServerSentEventTypeError,
Expand Down
15 changes: 9 additions & 6 deletions coderd/workspaceagents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
require.EqualValues(t, 10, manifest.Metadata[0].Interval)
require.EqualValues(t, 3, manifest.Metadata[0].Timeout)

post := func(key string, mr codersdk.WorkspaceAgentMetadataResult) {
post := func(ctx context.Context, key string, mr codersdk.WorkspaceAgentMetadataResult) {
err := agentClient.PostMetadata(ctx, agentsdk.PostMetadataRequest{
Metadata: []agentsdk.Metadata{
{
Expand All @@ -1073,8 +1073,11 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
Value: "bar",
}

// Setup is complete, reset the context.
ctx = testutil.Context(t, testutil.WaitMedium)

// Initial post must come before the Watch is established.
post("foo1", wantMetadata1)
post(ctx, "foo1", wantMetadata1)

updates, errors := client.WatchWorkspaceAgentMetadata(ctx, agentID)

Expand Down Expand Up @@ -1116,14 +1119,14 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
require.Zero(t, update[1].Result.CollectedAt)

wantMetadata2 := wantMetadata1
post("foo2", wantMetadata2)
post(ctx, "foo2", wantMetadata2)
update = recvUpdate()
require.Len(t, update, 3)
check(wantMetadata1, update[0], true)
check(wantMetadata2, update[1], true)

wantMetadata1.Error = "error"
post("foo1", wantMetadata1)
post(ctx, "foo1", wantMetadata1)
update = recvUpdate()
require.Len(t, update, 3)
check(wantMetadata1, update[0], true)
Expand All @@ -1133,7 +1136,7 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
tooLongValueMetadata.Value = strings.Repeat("a", maxValueLen*2)
tooLongValueMetadata.Error = ""
tooLongValueMetadata.CollectedAt = time.Now()
post("foo3", tooLongValueMetadata)
post(ctx, "foo3", tooLongValueMetadata)
got := recvUpdate()[2]
for i := 0; i < 2 && len(got.Result.Value) != maxValueLen; i++ {
got = recvUpdate()[2]
Expand All @@ -1142,7 +1145,7 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
require.NotEmpty(t, got.Result.Error)

unknownKeyMetadata := wantMetadata1
post("unknown", unknownKeyMetadata)
post(ctx, "unknown", unknownKeyMetadata)
}

type testWAMErrorStore struct {
Expand Down