test: ignore context.Canceled in acquireWithCancel (#17448)

fixes https://github.com/coder/internal/issues/584

Ignore canceled error when sending an acquired job, since dRPC is racy and will sometimes return this error even after successfully sending the job, if the test is quickly finished.
This commit is contained in:
Spike Curtis
2025-04-17 16:17:19 +04:00
committed by GitHub
parent daafa0d689
commit b3aba6dab7
+6 -1
View File
@@ -1270,6 +1270,11 @@ func (a *acquireOne) acquireWithCancel(stream proto.DRPCProvisionerDaemon_Acquir
return nil
}
err := stream.Send(a.job)
assert.NoError(a.t, err)
// dRPC is racy, and sometimes will return context.Canceled after it has successfully sent the message if we cancel
// right away, e.g. in unit tests that complete. So, just swallow the error in that case. If we are canceled before
// the job was acquired, presumably something else in the test will have failed.
if !xerrors.Is(err, context.Canceled) {
assert.NoError(a.t, err)
}
return nil
}