Skip to content

Commit c715185

Browse files
committed
fix tests
1 parent 72cf74a commit c715185

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

internal/pool/hooks_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ type TestHook struct {
1717
PutError error
1818
ShouldPool bool
1919
ShouldRemove bool
20+
ShouldAccept bool
2021
}
2122

22-
func (th *TestHook) OnGet(ctx context.Context, conn *Conn, isNewConn bool) error {
23+
func (th *TestHook) OnGet(ctx context.Context, conn *Conn, isNewConn bool) (bool, error) {
2324
th.OnGetCalled++
24-
return th.GetError
25+
return th.ShouldAccept, th.GetError
2526
}
2627

2728
func (th *TestHook) OnPut(ctx context.Context, conn *Conn) (shouldPool bool, shouldRemove bool, err error) {
@@ -42,8 +43,8 @@ func TestPoolHookManager(t *testing.T) {
4243
}
4344

4445
// Add hooks
45-
hook1 := &TestHook{ShouldPool: true}
46-
hook2 := &TestHook{ShouldPool: true}
46+
hook1 := &TestHook{ShouldPool: true, ShouldAccept: true}
47+
hook2 := &TestHook{ShouldPool: true, ShouldAccept: true}
4748

4849
manager.AddHook(hook1)
4950
manager.AddHook(hook2)
@@ -107,11 +108,12 @@ func TestHookErrorHandling(t *testing.T) {
107108

108109
// Hook that returns error on Get
109110
errorHook := &TestHook{
110-
GetError: errors.New("test error"),
111-
ShouldPool: true,
111+
GetError: errors.New("test error"),
112+
ShouldPool: true,
113+
ShouldAccept: true,
112114
}
113115

114-
normalHook := &TestHook{ShouldPool: true}
116+
normalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
115117

116118
manager.AddHook(errorHook)
117119
manager.AddHook(normalHook)
@@ -145,9 +147,10 @@ func TestHookShouldRemove(t *testing.T) {
145147
removeHook := &TestHook{
146148
ShouldPool: false,
147149
ShouldRemove: true,
150+
ShouldAccept: true,
148151
}
149152

150-
normalHook := &TestHook{ShouldPool: true}
153+
normalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
151154

152155
manager.AddHook(removeHook)
153156
manager.AddHook(normalHook)
@@ -181,7 +184,7 @@ func TestHookShouldRemove(t *testing.T) {
181184
func TestPoolWithHooks(t *testing.T) {
182185
// Create a pool with hooks
183186
hookManager := NewPoolHookManager()
184-
testHook := &TestHook{ShouldPool: true}
187+
testHook := &TestHook{ShouldPool: true, ShouldAccept: true}
185188
hookManager.AddHook(testHook)
186189

187190
opt := &Options{
@@ -208,7 +211,7 @@ func TestPoolWithHooks(t *testing.T) {
208211
}
209212

210213
// Test adding hook to pool
211-
additionalHook := &TestHook{ShouldPool: true}
214+
additionalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
212215
pool.AddPoolHook(additionalHook)
213216

214217
if pool.hookManager.GetHookCount() != 2 {

redis_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ var _ = Describe("Credentials Provider Priority", func() {
854854
credentials: initialCreds,
855855
updates: updatesChan,
856856
},
857+
PoolSize: 1, // Force single connection to ensure reauth is tested
857858
}
858859

859860
client = redis.NewClient(opt)
@@ -865,11 +866,16 @@ var _ = Describe("Credentials Provider Priority", func() {
865866

866867
// Update credentials
867868
opt.StreamingCredentialsProvider.(*mockStreamingProvider).updates <- updatedCreds
868-
// wrongpass
869-
time.Sleep(10 * time.Millisecond)
870-
Expect(client.Ping(context.Background()).Err()).To(HaveOccurred())
871-
time.Sleep(10 * time.Millisecond)
872-
Expect(recorder.Contains("AUTH updated_user")).To(BeTrue())
869+
870+
// Wait for reauth to complete and verify updated credentials are used
871+
// We need to keep trying Ping until we see the updated AUTH command
872+
// because the reauth happens asynchronously
873+
Eventually(func() bool {
874+
// wrongpass
875+
_ = client.Ping(context.Background()).Err()
876+
return recorder.Contains("AUTH updated_user")
877+
}, "1s", "50ms").Should(BeTrue())
878+
873879
close(updatesChan)
874880
})
875881
})

0 commit comments

Comments
 (0)