From 4a33370072f148ed0ef53845c97f121b3e3c3b4d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 23 Jul 2023 11:21:49 +0200 Subject: [PATCH] backend: Fix unreliable TestListCancel/Timeout test The test uses `WithTimeout` to create a context that cancels the List operation after a given delay. Several backends internally use a derived child context created using WithCancel. The cancellation of a context first closes the done channel of the context (here: the `WithTimeout` context) and _afterwards_ propagates the cancellation to child contexts (here: the `WithCancel` context). Therefor if the List implementation uses a child context, then it may take a moment until that context is also cancelled. Thus give the context cancellation a moment to propagate. --- internal/backend/test/tests.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/backend/test/tests.go b/internal/backend/test/tests.go index c2e5d0fc0..c03db79e3 100644 --- a/internal/backend/test/tests.go +++ b/internal/backend/test/tests.go @@ -428,6 +428,11 @@ func (s *Suite[C]) TestListCancel(t *testing.T) { // wait until the context is cancelled <-ctxTimeout.Done() + // The cancellation of a context first closes the done channel of the context and + // _afterwards_ propagates the cancellation to child contexts. If the List + // implementation uses a child context, then it may take a moment until that context + // is also cancelled. Thus give the context cancellation a moment to propagate. + time.Sleep(time.Millisecond) return nil })