Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba7d183

Browse files
authored
fix: fix flake in TestWorkspaceAgent_Metadata_CatchMemoryLeak (#13553)
Fixes flake seen here:https://github.com/coder/coder/actions/runs/9461246505/job/26061605278#13486 subtly changes the test so that `post` uses the new v2 Agent API, and when canceling context, there is a race condition where the yamux session underpinning the API can get torn down before the RPC processes the canceled context, yielding a different error response than the test was previously expecting.I've refactored the test to just stop posting when the test finishes, rather than depend on a context cancel to end the posting goroutine.
1 parent0c627a4 commitba7d183

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

‎coderd/workspaceagents_test.go‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ func TestWorkspaceAgent_Metadata_CatchMemoryLeak(t *testing.T) {
13501350
agentClient:=agentsdk.New(client.URL)
13511351
agentClient.SetSessionToken(r.AgentToken)
13521352

1353-
ctx,cancel:=context.WithCancel(testutil.Context(t,testutil.WaitSuperLong))
1353+
ctx:=testutil.Context(t,testutil.WaitSuperLong)
13541354
conn,err:=agentClient.ConnectRPC(ctx)
13551355
require.NoError(t,err)
13561356
deferfunc() {
@@ -1404,20 +1404,21 @@ func TestWorkspaceAgent_Metadata_CatchMemoryLeak(t *testing.T) {
14041404

14051405
postDone:=testutil.Go(t,func() {
14061406
for {
1407+
select {
1408+
case<-metadataDone:
1409+
return
1410+
default:
1411+
}
14071412
// We need to send two separate metadata updates to trigger the
14081413
// memory leak. foo2 will cause the number of foo1 to be doubled, etc.
1409-
err=post(ctx,"foo1","hi")
1414+
err:=post(ctx,"foo1","hi")
14101415
iferr!=nil {
1411-
if!xerrors.Is(err,context.Canceled) {
1412-
assert.NoError(t,err,"post metadata foo1")
1413-
}
1416+
assert.NoError(t,err,"post metadata foo1")
14141417
return
14151418
}
14161419
err=post(ctx,"foo2","bye")
14171420
iferr!=nil {
1418-
if!xerrors.Is(err,context.Canceled) {
1419-
assert.NoError(t,err,"post metadata foo1")
1420-
}
1421+
assert.NoError(t,err,"post metadata foo1")
14211422
return
14221423
}
14231424
}
@@ -1436,13 +1437,8 @@ func TestWorkspaceAgent_Metadata_CatchMemoryLeak(t *testing.T) {
14361437
// testing it is not straightforward.
14371438
db.err.Store(&wantErr)
14381439

1439-
select {
1440-
case<-ctx.Done():
1441-
t.Fatal("timeout waiting for SSE to close")
1442-
case<-metadataDone:
1443-
}
1444-
cancel()
1445-
<-postDone
1440+
testutil.RequireRecvCtx(ctx,t,metadataDone)
1441+
testutil.RequireRecvCtx(ctx,t,postDone)
14461442
}
14471443

14481444
funcTestWorkspaceAgent_Startup(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp