From b3aba6dab7fcba75a2f33b1f071051ce081ea737 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Thu, 17 Apr 2025 16:17:19 +0400 Subject: [PATCH] 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. --- provisionerd/provisionerd_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/provisionerd/provisionerd_test.go b/provisionerd/provisionerd_test.go index 8d5ba1621b..c711e0d492 100644 --- a/provisionerd/provisionerd_test.go +++ b/provisionerd/provisionerd_test.go @@ -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 }