Skip to content

Commit 0f1d4ac

Browse files
committed
fix tests
1 parent 9edd5f7 commit 0f1d4ac

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

cli/exp_mcp_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ func TestExpMcpServer(t *testing.T) {
3333
ctx := testutil.Context(t, testutil.WaitShort)
3434
cmdDone := make(chan struct{})
3535
cancelCtx, cancel := context.WithCancel(ctx)
36-
t.Cleanup(func() {
37-
cancel()
38-
<-cmdDone
39-
})
4036

4137
// Given: a running coder deployment
4238
client := coderdtest.New(t, nil)
@@ -93,6 +89,8 @@ func TestExpMcpServer(t *testing.T) {
9389
require.NoError(t, err, "should have received a valid JSON response from the tool")
9490
// Ensure the tool returns the expected user
9591
require.Contains(t, output, owner.UserID.String(), "should have received the expected user ID")
92+
cancel()
93+
<-cmdDone
9694
})
9795

9896
t.Run("OK", func(t *testing.T) {

coderd/workspaceagents_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ func TestWorkspaceAgentLogs(t *testing.T) {
341341

342342
func TestWorkspaceAgentAppStatus(t *testing.T) {
343343
t.Parallel()
344-
ctx := testutil.Context(t, testutil.WaitMedium)
345344
client, db := coderdtest.NewWithDatabase(t, nil)
346345
user := coderdtest.CreateFirstUser(t, client)
347346
client, user2 := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
@@ -362,6 +361,7 @@ func TestWorkspaceAgentAppStatus(t *testing.T) {
362361
agentClient.SetSessionToken(r.AgentToken)
363362
t.Run("Success", func(t *testing.T) {
364363
t.Parallel()
364+
ctx := testutil.Context(t, testutil.WaitShort)
365365
err := agentClient.PatchAppStatus(ctx, agentsdk.PatchAppStatus{
366366
AppSlug: "vscode",
367367
Message: "testing",
@@ -385,6 +385,7 @@ func TestWorkspaceAgentAppStatus(t *testing.T) {
385385

386386
t.Run("FailUnknownApp", func(t *testing.T) {
387387
t.Parallel()
388+
ctx := testutil.Context(t, testutil.WaitShort)
388389
err := agentClient.PatchAppStatus(ctx, agentsdk.PatchAppStatus{
389390
AppSlug: "unknown",
390391
Message: "testing",
@@ -399,6 +400,7 @@ func TestWorkspaceAgentAppStatus(t *testing.T) {
399400

400401
t.Run("FailUnknownState", func(t *testing.T) {
401402
t.Parallel()
403+
ctx := testutil.Context(t, testutil.WaitShort)
402404
err := agentClient.PatchAppStatus(ctx, agentsdk.PatchAppStatus{
403405
AppSlug: "vscode",
404406
Message: "testing",
@@ -413,6 +415,7 @@ func TestWorkspaceAgentAppStatus(t *testing.T) {
413415

414416
t.Run("FailTooLong", func(t *testing.T) {
415417
t.Parallel()
418+
ctx := testutil.Context(t, testutil.WaitShort)
416419
err := agentClient.PatchAppStatus(ctx, agentsdk.PatchAppStatus{
417420
AppSlug: "vscode",
418421
Message: strings.Repeat("a", 161),

codersdk/toolsdk/toolsdk.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ func WithCleanContext(h GenericHandlerFunc) GenericHandlerFunc {
156156
return func(parent context.Context, tb Deps, args json.RawMessage) (ret json.RawMessage, err error) {
157157
child, childCancel := context.WithCancel(context.Background())
158158
defer childCancel()
159+
// Ensure that the child context has the same deadline as the parent
160+
// context.
161+
if deadline, ok := parent.Deadline(); ok {
162+
deadlineCtx, deadlineCancel := context.WithDeadline(child, deadline)
163+
defer deadlineCancel()
164+
child = deadlineCtx
165+
}
159166
// Ensure that cancellation propagates from the parent context to the child context.
160167
go func() {
161168
select {
@@ -165,13 +172,6 @@ func WithCleanContext(h GenericHandlerFunc) GenericHandlerFunc {
165172
childCancel()
166173
}
167174
}()
168-
// Also ensure that the child context has the same deadline as the parent
169-
// context.
170-
if deadline, ok := parent.Deadline(); ok {
171-
deadlineCtx, deadlineCancel := context.WithDeadline(child, deadline)
172-
defer deadlineCancel()
173-
child = deadlineCtx
174-
}
175175
return h(child, tb, args)
176176
}
177177
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy