@@ -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.
0 commit comments