Skip to content

Commit e208cfb

Browse files
authored
fix: add missing wg.Wait() in flaky storage cache test (#2151)
1 parent 8b23683 commit e208cfb

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

packages/orchestrator/internal/sandbox/block/streaming_chunk_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,15 @@ func TestStreamingChunker_FullChunkCachedAfterPartialRequest(t *testing.T) {
283283
require.NoError(t, err)
284284

285285
// The background goroutine should continue fetching the remaining data.
286-
// Wait for it to complete.
287-
require.Eventually(t, func() bool {
288-
// Try reading the LAST block — if the full chunk is cached this
289-
// will succeed without opening another range reader.
290-
lastOff := int64(storage.MemoryChunkSize) - testBlockSize
291-
slice, err := chunker.Slice(t.Context(), lastOff, testBlockSize)
292-
if err != nil {
293-
return false
294-
}
286+
// Use a blocking Slice call (with timeout) instead of require.Eventually
287+
// to avoid racing condition goroutines against defer chunker.Close().
288+
lastOff := int64(storage.MemoryChunkSize) - testBlockSize
289+
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
290+
defer cancel()
295291

296-
return bytes.Equal(data[lastOff:], slice)
297-
}, 5*time.Second, 10*time.Millisecond)
292+
slice, err := chunker.Slice(ctx, lastOff, testBlockSize)
293+
require.NoError(t, err)
294+
require.True(t, bytes.Equal(data[lastOff:], slice))
298295

299296
// Exactly one OpenRangeReader call should have been made for the entire
300297
// chunk, not one per requested block.

packages/shared/pkg/storage/storage_cache_seekable_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ func TestCachedSeekable_ReadAt_PreservesEOF(t *testing.T) {
524524
n, err := c.ReadAt(t.Context(), buff, 0)
525525
assert.Equal(t, 3, n)
526526
require.ErrorIs(t, err, io.EOF, "cachedSeekable must not swallow io.EOF")
527+
528+
c.wg.Wait()
527529
})
528530

529531
t.Run("nil error from inner is returned to caller unchanged", func(t *testing.T) {

0 commit comments

Comments
 (0)