mirror of
https://github.com/redis/go-redis.git
synced 2025-07-29 17:41:15 +03:00
fix(tests): add global ctx in tests
This commit is contained in:
@ -16,6 +16,8 @@ import (
|
|||||||
. "github.com/bsm/gomega"
|
. "github.com/bsm/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ctx = context.TODO()
|
||||||
|
|
||||||
var _ = Describe("newClusterState", func() {
|
var _ = Describe("newClusterState", func() {
|
||||||
var state *clusterState
|
var state *clusterState
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package push
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9/internal"
|
"github.com/redis/go-redis/v9/internal"
|
||||||
"github.com/redis/go-redis/v9/internal/proto"
|
"github.com/redis/go-redis/v9/internal/proto"
|
||||||
@ -52,23 +51,8 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx
|
|||||||
if rd == nil {
|
if rd == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
conn := handlerCtx.Conn
|
|
||||||
if conn == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
netConn := handlerCtx.Conn.GetNetConn()
|
|
||||||
if netConn == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
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
|
// Check if there's data available to read
|
||||||
replyType, err := rd.PeekReplyType()
|
replyType, err := rd.PeekReplyType()
|
||||||
if err != nil {
|
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
|
// VoidProcessor discards all push notifications without processing them
|
||||||
@ -154,20 +138,8 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt
|
|||||||
if rd == nil {
|
if rd == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
conn := handlerCtx.Conn
|
|
||||||
if conn == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
netConn := handlerCtx.Conn.GetNetConn()
|
|
||||||
if netConn == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for {
|
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
|
// Check if there's data available to read
|
||||||
replyType, err := rd.PeekReplyType()
|
replyType, err := rd.PeekReplyType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -196,7 +168,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return netConn.SetReadDeadline(time.Time{})
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// willHandleNotificationInClient checks if a notification type should be ignored by the push notification
|
// 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 {
|
func willHandleNotificationInClient(notificationType string) bool {
|
||||||
switch notificationType {
|
switch notificationType {
|
||||||
// Pub/Sub notifications - handled by pub/sub system
|
// 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
|
"pmessage", // Pattern pub/sub message
|
||||||
"subscribe", // Subscription confirmation
|
"subscribe", // Subscription confirmation
|
||||||
"unsubscribe", // Unsubscription confirmation
|
"unsubscribe", // Unsubscription confirmation
|
||||||
|
Reference in New Issue
Block a user