mirror of https://github.com/coder/coder.git
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:
parent
b0aa91bf27
commit
e36503afd2
|
@ -338,9 +338,12 @@ func TestStartupLogsSender(t *testing.T) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
defer cancel()
|
||||
|
||||
var want, got []agentsdk.Log
|
||||
patchLogs := func(_ context.Context, req agentsdk.PatchLogs) error {
|
||||
got = append(got, req.Logs...)
|
||||
patchStart := make(chan struct{})
|
||||
patchDone := make(chan struct{})
|
||||
patchLogs := func(ctx context.Context, _ agentsdk.PatchLogs) error {
|
||||
close(patchStart)
|
||||
<-ctx.Done()
|
||||
close(patchDone)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -358,10 +361,14 @@ func TestStartupLogsSender(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
cancel()
|
||||
go func() {
|
||||
<-patchStart
|
||||
cancel()
|
||||
}()
|
||||
err = flushAndClose(ctx)
|
||||
require.Error(t, err)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
<-patchDone
|
||||
// The patch request should have been canceled if it was active.
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue