(t *testing.T)
| 439 | } |
| 440 | |
| 441 | func TestAsyncBufferThreshold(t *testing.T) { |
| 442 | _, bytesReader := generateSourceData(t, asyncbuffer.PauseThreshold*3) |
| 443 | ab := asyncbuffer.New(bytesReader, -1) |
| 444 | defer ab.Close() |
| 445 | |
| 446 | target := make([]byte, asyncbuffer.ChunkSize) |
| 447 | n, err := ab.ReadAt(target, 0) |
| 448 | require.NoError(t, err) |
| 449 | assert.Equal(t, asyncbuffer.ChunkSize, n) |
| 450 | |
| 451 | // Ensure that buffer hits the pause threshold |
| 452 | require.Eventually(t, func() bool { |
| 453 | return bytesReader.BytesRead() >= asyncbuffer.PauseThreshold |
| 454 | }, 300*time.Millisecond, 10*time.Millisecond) |
| 455 | |
| 456 | // Ensure that buffer never reaches the end of the stream |
| 457 | require.Never(t, func() bool { |
| 458 | return bytesReader.BytesRead() >= asyncbuffer.PauseThreshold*2-1 |
| 459 | }, 300*time.Millisecond, 10*time.Millisecond) |
| 460 | |
| 461 | // Let's hit the pause threshold |
| 462 | target = make([]byte, asyncbuffer.PauseThreshold) |
| 463 | n, err = ab.ReadAt(target, 0) |
| 464 | require.NoError(t, err) |
| 465 | require.Equal(t, asyncbuffer.PauseThreshold, n) |
| 466 | |
| 467 | // Ensure that buffer never reaches the end of the stream |
| 468 | require.Never(t, func() bool { |
| 469 | return bytesReader.BytesRead() >= asyncbuffer.PauseThreshold*2-1 |
| 470 | }, 300*time.Millisecond, 10*time.Millisecond) |
| 471 | |
| 472 | // Let's hit the pause threshold |
| 473 | target = make([]byte, asyncbuffer.PauseThreshold+1) |
| 474 | n, err = ab.ReadAt(target, 0) |
| 475 | require.NoError(t, err) |
| 476 | |
| 477 | // It usually returns only pauseThreshold bytes because this exact operation unpauses the reader, |
| 478 | // but the initial offset is before the threshold, data beyond the threshold may not be available. |
| 479 | assert.GreaterOrEqual(t, asyncbuffer.PauseThreshold, n) |
| 480 | |
| 481 | // Ensure that buffer hits the end of the stream |
| 482 | require.Eventually(t, func() bool { |
| 483 | return bytesReader.BytesRead() >= asyncbuffer.PauseThreshold*2 |
| 484 | }, 300*time.Millisecond, 10*time.Millisecond) |
| 485 | } |
| 486 | |
| 487 | func TestAsyncBufferThresholdInstantBeyondAccess(t *testing.T) { |
| 488 | _, bytesReader := generateSourceData(t, asyncbuffer.PauseThreshold*3) |
nothing calls this directly
no test coverage detected