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.
This commit is contained in:
Michael Eischer 2023-07-23 11:21:49 +02:00
parent 98fb56baa6
commit 4a33370072

View file

@ -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
})