diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-01-30 12:20:28 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-01-30 12:23:31 +0300 |
commit | 0a3ea6f8b4b7e1ffefeedfb2e1581f33460e47b5 (patch) | |
tree | f32dd056403c02837e1ad4746cd8567f5f89bc3b | |
parent | 9e9717d60e83bc08e6bcb3ca0e636edf1668a9b3 (diff) |
streamcache: Improve test for pipe backpressure
One of our streamcache tests verifies that the backpressure blocks the
writer until readers consume its output. This test is flaky though as we
wait for 10ms to have read the first two bytes, but some of our testing
machines are seemingly slow enough to not catch up in time:
=== FAIL: internal/streamcache TestPipe_backpressure (1.00s)
pipe_test.go:139:
Error Trace: /Users/gitlab/builds/gitlab-org/gitaly/internal/streamcache/pipe_test.go:139
Error: Not equal:
expected: 2
actual : 1
Test: TestPipe_backpressure
Messages: writer should be blocked after 2 bytes
While it would be great to fix this test so that we don't need any
timeouts in the first place, I have no idea how to achieve this as we
are essentially waiting for something to _not_ happen. So instead, let's
just extend the timeout to wait for the event to happen for a full
minute and then check we're not making further progress afterwards for
another 10 milliseconds.
-rw-r--r-- | internal/streamcache/pipe_test.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/streamcache/pipe_test.go b/internal/streamcache/pipe_test.go index 3917c717c..ffc9f63b3 100644 --- a/internal/streamcache/pipe_test.go +++ b/internal/streamcache/pipe_test.go @@ -135,6 +135,11 @@ func TestPipe_backpressure(t *testing.T) { _, err := io.ReadFull(pr, buf) require.NoError(t, err) output = append(output, buf...) + require.Eventually(t, func() bool { + return atomic.LoadInt64(&wprogress) == 2 + }, time.Minute, time.Millisecond, "writer should have read 2 bytes") + + // We should not see any progress until we try to read more bytes. time.Sleep(10 * time.Millisecond) require.Equal(t, int64(2), atomic.LoadInt64(&wprogress), "writer should be blocked after 2 bytes") |