From 225c0bf5b2c84f9f59ae5509faaa84e2e13b2ae0 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Sat, 5 Jul 2025 13:18:00 +0300 Subject: [PATCH] fix(tests): add global ctx in tests --- internal_test.go | 2 ++ push/processor.go | 36 ++++-------------------------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/internal_test.go b/internal_test.go index 4a655cff..3d9f0205 100644 --- a/internal_test.go +++ b/internal_test.go @@ -16,6 +16,8 @@ import ( . "github.com/bsm/gomega" ) +var ctx = context.TODO() + var _ = Describe("newClusterState", func() { var state *clusterState diff --git a/push/processor.go b/push/processor.go index 433a546b..2c1b6f5e 100644 --- a/push/processor.go +++ b/push/processor.go @@ -2,7 +2,6 @@ package push import ( "context" - "time" "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/proto" @@ -52,23 +51,8 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx if rd == nil { return nil } - conn := handlerCtx.Conn - if conn == nil { - return nil - } - netConn := handlerCtx.Conn.GetNetConn() - if netConn == nil { - return nil - } for { - // Set a short read deadline to check for available data - // otherwise we may block on Peek if there is no data available - err := netConn.SetReadDeadline(time.Now().Add(1)) - if err != nil { - return err - } - // Check if there's data available to read replyType, err := rd.PeekReplyType() if err != nil { @@ -120,7 +104,7 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx } } - return netConn.SetReadDeadline(time.Time{}) + return nil } // VoidProcessor discards all push notifications without processing them @@ -154,20 +138,8 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt if rd == nil { return nil } - conn := handlerCtx.Conn - if conn == nil { - return nil - } - netConn := handlerCtx.Conn.GetNetConn() - if netConn == nil { - return nil - } + for { - // Set a short read deadline to check for available data - err := netConn.SetReadDeadline(time.Now().Add(1)) - if err != nil { - return err - } // Check if there's data available to read replyType, err := rd.PeekReplyType() if err != nil { @@ -196,7 +168,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt return nil } } - return netConn.SetReadDeadline(time.Time{}) + return nil } // willHandleNotificationInClient checks if a notification type should be ignored by the push notification @@ -204,7 +176,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt func willHandleNotificationInClient(notificationType string) bool { switch notificationType { // Pub/Sub notifications - handled by pub/sub system - case "message", // Regular pub/sub message + case "message", // Regular pub/sub message "pmessage", // Pattern pub/sub message "subscribe", // Subscription confirmation "unsubscribe", // Unsubscription confirmation