@@ -138,6 +138,7 @@ func TestBackedWriter_WriteToUnderlyingWhenConnected(t *testing.T) {
138
138
require .Equal (t , 5 , n )
139
139
140
140
// Data should be buffered
141
+ require .Equal (t , uint64 (5 ), bw .SequenceNum ())
141
142
142
143
// Check underlying writer
143
144
require .Equal (t , []byte ("hello" ), writer .buffer .Bytes ())
@@ -158,7 +159,7 @@ func TestBackedWriter_BlockOnWriteFailure(t *testing.T) {
158
159
// Cause write to fail
159
160
writer .setError (xerrors .New ("write failed" ))
160
161
161
- // Write should block when underlying writer fails
162
+ // Write should block when underlying writer fails, not succeed immediately
162
163
writeComplete := make (chan struct {})
163
164
var writeErr error
164
165
var n int
@@ -376,6 +377,7 @@ func TestBackedWriter_BufferEviction(t *testing.T) {
376
377
err = bw .Reconnect (2 , writer3 ) // From sequence 2, should replay "cdefg"
377
378
require .NoError (t , err )
378
379
require .Equal (t , []byte ("cdefg" ), writer3 .buffer .Bytes ())
380
+ require .True (t , bw .Connected ())
379
381
}
380
382
381
383
func TestBackedWriter_Close (t * testing.T ) {
@@ -414,39 +416,6 @@ func TestBackedWriter_CloseIdempotent(t *testing.T) {
414
416
require .NoError (t , err )
415
417
}
416
418
417
- func TestBackedWriter_ConcurrentWrites (t * testing.T ) {
418
- t .Parallel ()
419
-
420
- errorChan := make (chan error , 1 )
421
- bw := backedpipe .NewBackedWriter (backedpipe .DefaultBufferSize , errorChan )
422
- writer := newMockWriter ()
423
- bw .Reconnect (0 , writer )
424
-
425
- var wg sync.WaitGroup
426
- numWriters := 10
427
- writesPerWriter := 50
428
-
429
- for i := 0 ; i < numWriters ; i ++ {
430
- wg .Add (1 )
431
- go func (id int ) {
432
- defer wg .Done ()
433
- for j := 0 ; j < writesPerWriter ; j ++ {
434
- data := []byte {byte (id + '0' )}
435
- bw .Write (data )
436
- }
437
- }(i )
438
- }
439
-
440
- wg .Wait ()
441
-
442
- // Should have written expected amount to buffer
443
- expectedBytes := uint64 (numWriters * writesPerWriter ) //nolint:gosec // Safe conversion: test constants with small values
444
- require .Equal (t , expectedBytes , bw .SequenceNum ())
445
- // Note: underlying writer may not receive all bytes due to potential disconnections
446
- // during concurrent operations, but the buffer should track all writes
447
- require .True (t , writer .Len () <= int (expectedBytes )) //nolint:gosec // Safe conversion: expectedBytes is calculated from small test values
448
- }
449
-
450
419
func TestBackedWriter_ReconnectDuringReplay (t * testing.T ) {
451
420
t .Parallel ()
452
421
@@ -463,9 +432,7 @@ func TestBackedWriter_ReconnectDuringReplay(t *testing.T) {
463
432
464
433
// Create a writer that fails during replay
465
434
writer2 := & mockWriter {
466
- writeFunc : func (p []byte ) (int , error ) {
467
- return 0 , xerrors .New ("replay failed" )
468
- },
435
+ err : backedpipe .ErrReplayFailed ,
469
436
}
470
437
471
438
err = bw .Reconnect (0 , writer2 )
0 commit comments