mirror of
https://github.com/redis/go-redis.git
synced 2025-11-04 02:33:24 +03:00
* fix(pool): wip, pool reauth should not interfere with handoff * fix credListeners map * fix race in tests * better conn usable timeout * add design decision comment * few small improvements * update marked as queued * add Used to clarify the state of the conn * rename test * fix(test): fix flaky test * lock inside the listeners collection * address pr comments * Update internal/auth/cred_listeners.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/pool/buffer_size_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * wip refactor entraid * fix maintnotif pool hook * fix mocks * fix nil listener * sync and async reauth based on conn lifecycle * be able to reject connection OnGet * pass hooks so the tests can observe reauth * give some time for the background to execute commands * fix tests * only async reauth * Update internal/pool/pool.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/auth/streaming/pool_hook.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/pool/conn.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore(redisotel): use metric.WithAttributeSet to avoid copy (#3552) In order to improve performance replace `WithAttributes` with `WithAttributeSet`. This avoids the slice allocation and copy that is done in `WithAttributes`. For more information see https://github.com/open-telemetry/opentelemetry-go/blob/v1.38.0/metric/instrument.go#L357-L376 * chore(docs): explain why MaxRetries is disabled for ClusterClient (#3551) Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com> * exponential backoff * address pr comments * address pr comments * remove rlock * add some comments * add comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Warnar Boekkooi <wboekkooi@impossiblecloud.com> Co-authored-by: Justin <justindsouza80@gmail.com>
102 lines
3.0 KiB
Go
102 lines
3.0 KiB
Go
package streaming
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/redis/go-redis/v9/auth"
|
|
"github.com/redis/go-redis/v9/internal/pool"
|
|
)
|
|
|
|
// Test that Listener returns the newly created listener, not nil
|
|
func TestManager_Listener_ReturnsNewListener(t *testing.T) {
|
|
// Create a mock pool
|
|
mockPool := &mockPooler{}
|
|
|
|
// Create manager
|
|
manager := NewManager(mockPool, time.Second)
|
|
|
|
// Create a mock connection
|
|
conn := &pool.Conn{}
|
|
|
|
// Mock functions
|
|
reAuth := func(cn *pool.Conn, creds auth.Credentials) error {
|
|
return nil
|
|
}
|
|
|
|
onErr := func(cn *pool.Conn, err error) {
|
|
}
|
|
|
|
// Get listener - this should create a new one
|
|
listener, err := manager.Listener(conn, reAuth, onErr)
|
|
|
|
// Verify no error
|
|
if err != nil {
|
|
t.Fatalf("Expected no error, got: %v", err)
|
|
}
|
|
|
|
// Verify listener is not nil (this was the bug!)
|
|
if listener == nil {
|
|
t.Fatal("Expected listener to be non-nil, but got nil")
|
|
}
|
|
|
|
// Verify it's the correct type
|
|
if _, ok := listener.(*ConnReAuthCredentialsListener); !ok {
|
|
t.Fatalf("Expected listener to be *ConnReAuthCredentialsListener, got %T", listener)
|
|
}
|
|
|
|
// Get the same listener again - should return the existing one
|
|
listener2, err := manager.Listener(conn, reAuth, onErr)
|
|
if err != nil {
|
|
t.Fatalf("Expected no error on second call, got: %v", err)
|
|
}
|
|
|
|
if listener2 == nil {
|
|
t.Fatal("Expected listener2 to be non-nil")
|
|
}
|
|
|
|
// Should be the same instance
|
|
if listener != listener2 {
|
|
t.Error("Expected to get the same listener instance on second call")
|
|
}
|
|
}
|
|
|
|
// Test that Listener returns error when conn is nil
|
|
func TestManager_Listener_NilConn(t *testing.T) {
|
|
mockPool := &mockPooler{}
|
|
manager := NewManager(mockPool, time.Second)
|
|
|
|
listener, err := manager.Listener(nil, nil, nil)
|
|
|
|
if err == nil {
|
|
t.Fatal("Expected error when conn is nil, got nil")
|
|
}
|
|
|
|
if listener != nil {
|
|
t.Error("Expected listener to be nil when error occurs")
|
|
}
|
|
|
|
expectedErr := "poolCn cannot be nil"
|
|
if err.Error() != expectedErr {
|
|
t.Errorf("Expected error message %q, got %q", expectedErr, err.Error())
|
|
}
|
|
}
|
|
|
|
// Mock pooler for testing
|
|
type mockPooler struct{}
|
|
|
|
func (m *mockPooler) NewConn(ctx context.Context) (*pool.Conn, error) { return nil, nil }
|
|
func (m *mockPooler) CloseConn(*pool.Conn) error { return nil }
|
|
func (m *mockPooler) Get(ctx context.Context) (*pool.Conn, error) { return nil, nil }
|
|
func (m *mockPooler) Put(ctx context.Context, conn *pool.Conn) {}
|
|
func (m *mockPooler) Remove(ctx context.Context, conn *pool.Conn, reason error) {}
|
|
func (m *mockPooler) Len() int { return 0 }
|
|
func (m *mockPooler) IdleLen() int { return 0 }
|
|
func (m *mockPooler) Stats() *pool.Stats { return &pool.Stats{} }
|
|
func (m *mockPooler) Size() int { return 10 }
|
|
func (m *mockPooler) AddPoolHook(hook pool.PoolHook) {}
|
|
func (m *mockPooler) RemovePoolHook(hook pool.PoolHook) {}
|
|
func (m *mockPooler) Close() error { return nil }
|
|
|