Skip to content

Commit 2f1d17e

Browse files
committed
fix(tests): simulate start/stop in mock credentials provider
1 parent c5054e2 commit 2f1d17e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

redis_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -839,14 +839,15 @@ var _ = Describe("Credentials Provider Priority", func() {
839839
Expect(recorder.Contains("AUTH")).To(BeFalse())
840840
})
841841

842-
It("should handle credential updates from streaming provider", func() {
842+
FIt("should handle credential updates from streaming provider", func() {
843843
initialCreds := auth.NewBasicCredentials("initial_user", "initial_pass")
844844
updatedCreds := auth.NewBasicCredentials("updated_user", "updated_pass")
845+
updatesChan := make(chan auth.Credentials, 1)
845846

846847
opt = &redis.Options{
847848
StreamingCredentialsProvider: &mockStreamingProvider{
848849
credentials: initialCreds,
849-
updates: make(chan auth.Credentials, 1),
850+
updates: updatesChan,
850851
},
851852
}
852853

@@ -861,6 +862,7 @@ var _ = Describe("Credentials Provider Priority", func() {
861862
// wrongpass
862863
Expect(client.Ping(context.Background()).Err()).To(HaveOccurred())
863864
Expect(recorder.Contains("AUTH updated_user")).To(BeTrue())
865+
close(updatesChan)
864866
})
865867
})
866868

@@ -875,12 +877,10 @@ func (m *mockStreamingProvider) Subscribe(listener auth.CredentialsListener) (au
875877
return nil, nil, m.err
876878
}
877879

878-
// Send initial credentials
879-
listener.OnNext(m.credentials)
880-
881880
// Start goroutine to handle updates
882881
go func() {
883882
for creds := range m.updates {
883+
m.credentials = creds
884884
listener.OnNext(creds)
885885
}
886886
}()
@@ -892,7 +892,6 @@ func (m *mockStreamingProvider) Subscribe(listener auth.CredentialsListener) (au
892892
// allow multiple closes from multiple listeners
893893
}
894894
}()
895-
close(m.updates)
896895
return
897896
}, nil
898897
}

0 commit comments

Comments
 (0)