@@ -152,6 +152,7 @@ func TestBackedPipe_NewBackedPipe(t *testing.T) {
152
152
reconnectFn , _ , _ := mockReconnectFunc (newMockConnection ())
153
153
154
154
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
155
+ defer bp .Close ()
155
156
require .NotNil (t , bp )
156
157
require .False (t , bp .Connected ())
157
158
}
@@ -164,6 +165,7 @@ func TestBackedPipe_Connect(t *testing.T) {
164
165
reconnectFn , callCount , _ := mockReconnectFunc (conn )
165
166
166
167
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
168
+ defer bp .Close ()
167
169
168
170
err := bp .Connect (ctx )
169
171
require .NoError (t , err )
@@ -179,6 +181,7 @@ func TestBackedPipe_ConnectAlreadyConnected(t *testing.T) {
179
181
reconnectFn , _ , _ := mockReconnectFunc (conn )
180
182
181
183
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
184
+ defer bp .Close ()
182
185
183
186
err := bp .Connect (ctx )
184
187
require .NoError (t , err )
@@ -214,6 +217,7 @@ func TestBackedPipe_BasicReadWrite(t *testing.T) {
214
217
reconnectFn , _ , _ := mockReconnectFunc (conn )
215
218
216
219
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
220
+ defer bp .Close ()
217
221
218
222
err := bp .Connect (ctx )
219
223
require .NoError (t , err )
@@ -242,6 +246,7 @@ func TestBackedPipe_WriteBeforeConnect(t *testing.T) {
242
246
reconnectFn , _ , _ := mockReconnectFunc (conn )
243
247
244
248
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
249
+ defer bp .Close ()
245
250
246
251
// Write before connecting should succeed (buffered)
247
252
n , err := bp .Write ([]byte ("hello" ))
@@ -263,6 +268,7 @@ func TestBackedPipe_ReadBlocksWhenDisconnected(t *testing.T) {
263
268
reconnectFn , _ , _ := mockReconnectFunc (newMockConnection ())
264
269
265
270
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
271
+ defer bp .Close ()
266
272
267
273
// Start a read that should block
268
274
readDone := make (chan struct {})
@@ -311,6 +317,7 @@ func TestBackedPipe_Reconnection(t *testing.T) {
311
317
reconnectFn , _ , signalChan := mockReconnectFunc (conn1 , conn2 )
312
318
313
319
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
320
+ defer bp .Close ()
314
321
315
322
// Initial connect
316
323
err := bp .Connect (ctx )
@@ -392,6 +399,7 @@ func TestBackedPipe_WaitForConnection(t *testing.T) {
392
399
reconnectFn , _ , _ := mockReconnectFunc (conn )
393
400
394
401
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
402
+ defer bp .Close ()
395
403
396
404
// Should timeout when not connected
397
405
// Use a shorter timeout for this test to speed up test runs
@@ -426,6 +434,7 @@ func TestBackedPipe_ConcurrentReadWrite(t *testing.T) {
426
434
reconnectFn , _ , _ := mockReconnectFunc (conn )
427
435
428
436
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
437
+ defer bp .Close ()
429
438
430
439
err := bp .Connect (ctx )
431
440
require .NoError (t , err )
@@ -514,6 +523,7 @@ func TestBackedPipe_ReconnectFunctionFailure(t *testing.T) {
514
523
}
515
524
516
525
bp := backedpipe .NewBackedPipe (ctx , failingReconnectFn )
526
+ defer bp .Close ()
517
527
518
528
err := bp .Connect (ctx )
519
529
require .Error (t , err )
@@ -530,6 +540,7 @@ func TestBackedPipe_ForceReconnect(t *testing.T) {
530
540
reconnectFn , callCount , _ := mockReconnectFunc (conn1 , conn2 )
531
541
532
542
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
543
+ defer bp .Close ()
533
544
534
545
// Initial connect
535
546
err := bp .Connect (ctx )
@@ -543,7 +554,7 @@ func TestBackedPipe_ForceReconnect(t *testing.T) {
543
554
require .Equal (t , "test data" , conn1 .ReadString ())
544
555
545
556
// Force a reconnection
546
- err = bp .ForceReconnect (ctx )
557
+ err = bp .ForceReconnect ()
547
558
require .NoError (t , err )
548
559
require .True (t , bp .Connected ())
549
560
require .Equal (t , 2 , * callCount )
@@ -580,7 +591,7 @@ func TestBackedPipe_ForceReconnectWhenClosed(t *testing.T) {
580
591
require .NoError (t , err )
581
592
582
593
// Try to force reconnect when closed
583
- err = bp .ForceReconnect (ctx )
594
+ err = bp .ForceReconnect ()
584
595
require .Error (t , err )
585
596
require .Equal (t , io .ErrClosedPipe , err )
586
597
}
@@ -593,9 +604,10 @@ func TestBackedPipe_ForceReconnectWhenDisconnected(t *testing.T) {
593
604
reconnectFn , callCount , _ := mockReconnectFunc (conn )
594
605
595
606
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
607
+ defer bp .Close ()
596
608
597
609
// Don't connect initially, just force reconnect
598
- err := bp .ForceReconnect (ctx )
610
+ err := bp .ForceReconnect ()
599
611
require .NoError (t , err )
600
612
require .True (t , bp .Connected ())
601
613
require .Equal (t , 1 , * callCount )
@@ -655,6 +667,7 @@ func TestBackedPipe_EOFTriggersReconnection(t *testing.T) {
655
667
}
656
668
657
669
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
670
+ defer bp .Close ()
658
671
659
672
// Initial connect
660
673
err := bp .Connect (ctx )
@@ -699,6 +712,9 @@ func BenchmarkBackedPipe_Write(b *testing.B) {
699
712
700
713
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
701
714
bp .Connect (ctx )
715
+ b .Cleanup (func () {
716
+ _ = bp .Close ()
717
+ })
702
718
703
719
data := make ([]byte , 1024 ) // 1KB writes
704
720
@@ -715,6 +731,9 @@ func BenchmarkBackedPipe_Read(b *testing.B) {
715
731
716
732
bp := backedpipe .NewBackedPipe (ctx , reconnectFn )
717
733
bp .Connect (ctx )
734
+ b .Cleanup (func () {
735
+ _ = bp .Close ()
736
+ })
718
737
719
738
buf := make ([]byte , 1024 )
720
739
0 commit comments