Skip to content

Commit 06b9d55

Browse files
zeripath6543
andauthored
Timeout on flush in testing (#16864)
* Timeout on flush in testing At the end of each test the queues are flushed. At present there is no limit on the length of time a flush can take which can lead to long flushes. However, if the CI task is cancelled we lose the log information as to where the long flush was taking place. This PR simply adds a default time limit of 2 minutes - at which point an error will be produced. This should allow us to more easily find the culprit. Signed-off-by: Andrew Thornton <[email protected]> * return better error Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent b0ff429 commit 06b9d55

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

integrations/testlogger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) func() {
121121
fmt.Fprintf(os.Stdout, "+++ %s ... still flushing after %v ...\n", t.Name(), slowFlush)
122122
}
123123
})
124-
if err := queue.GetManager().FlushAll(context.Background(), -1); err != nil {
124+
if err := queue.GetManager().FlushAll(context.Background(), 2*time.Minute); err != nil {
125125
t.Errorf("Flushing queues failed with error %v", err)
126126
}
127127
timer.Stop()

modules/queue/manager.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"reflect"
1111
"sort"
12+
"strings"
1213
"sync"
1314
"time"
1415

@@ -169,7 +170,17 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
169170
for {
170171
select {
171172
case <-ctx.Done():
172-
return ctx.Err()
173+
mqs := m.ManagedQueues()
174+
nonEmptyQueues := []string{}
175+
for _, mq := range mqs {
176+
if !mq.IsEmpty() {
177+
nonEmptyQueues = append(nonEmptyQueues, mq.Name)
178+
}
179+
}
180+
if len(nonEmptyQueues) > 0 {
181+
return fmt.Errorf("flush timeout with non-empty queues: %s", strings.Join(nonEmptyQueues, ", "))
182+
}
183+
return nil
173184
default:
174185
}
175186
mqs := m.ManagedQueues()

0 commit comments

Comments
 (0)