Skip to content

Commit 1806952

Browse files
committed
race in test
1 parent c5c05a3 commit 1806952

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hitless/pool_hook_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net"
88
"sync"
9+
"sync/atomic"
910
"testing"
1011
"time"
1112

@@ -919,7 +920,7 @@ func TestConnectionHook(t *testing.T) {
919920
}
920921

921922
// Set a dialer that will check the context timeout
922-
timeoutVerified := false
923+
var timeoutVerified int32 // Use atomic for thread safety
923924
conn.SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
924925
// Check that the context has the expected timeout
925926
deadline, ok := ctx.Deadline()
@@ -935,7 +936,7 @@ func TestConnectionHook(t *testing.T) {
935936
t.Errorf("Context deadline not as expected. Expected around %v, got %v (diff: %v)",
936937
expectedDeadline, deadline, timeDiff)
937938
} else {
938-
timeoutVerified = true
939+
atomic.StoreInt32(&timeoutVerified, 1)
939940
}
940941

941942
return nil // Successful handoff
@@ -955,7 +956,7 @@ func TestConnectionHook(t *testing.T) {
955956
// Wait for handoff to complete
956957
time.Sleep(500 * time.Millisecond)
957958

958-
if !timeoutVerified {
959+
if atomic.LoadInt32(&timeoutVerified) == 0 {
959960
t.Error("HandoffTimeout was not properly applied to context")
960961
}
961962

0 commit comments

Comments
 (0)