mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
test(codersdk/agentsdk): fix context cancel flush test (#10560)
This change tests that the patch request is cancelled instead of hoping that there's no race between context cancellations leading to patch never being called.
This commit is contained in:
committed by
GitHub
parent
b0aa91bf27
commit
e36503afd2
@ -338,9 +338,12 @@ func TestStartupLogsSender(t *testing.T) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var want, got []agentsdk.Log
|
patchStart := make(chan struct{})
|
||||||
patchLogs := func(_ context.Context, req agentsdk.PatchLogs) error {
|
patchDone := make(chan struct{})
|
||||||
got = append(got, req.Logs...)
|
patchLogs := func(ctx context.Context, _ agentsdk.PatchLogs) error {
|
||||||
|
close(patchStart)
|
||||||
|
<-ctx.Done()
|
||||||
|
close(patchDone)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,10 +361,14 @@ func TestStartupLogsSender(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
cancel()
|
go func() {
|
||||||
|
<-patchStart
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
err = flushAndClose(ctx)
|
err = flushAndClose(ctx)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
require.Equal(t, want, got)
|
<-patchDone
|
||||||
|
// The patch request should have been canceled if it was active.
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user