From 409dac11cfeac10a416523adfbd02943ab2117a9 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Wed, 16 Jul 2025 20:45:45 +0300 Subject: [PATCH] fix(push): fix tests --- commands_test.go | 3 ++- push/push_test.go | 16 ++++++++-------- redis.go | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/commands_test.go b/commands_test.go index 19548e13..a5592e2c 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2948,7 +2948,8 @@ var _ = Describe("Commands", func() { res, err = client.HPTTL(ctx, "myhash", "key1", "key2", "key200").Result() Expect(err).NotTo(HaveOccurred()) - Expect(res[0]).To(BeNumerically("~", 10*time.Second.Milliseconds(), 1)) + // overhead of the push notification check is about 1-2ms for 100 commands + Expect(res[0]).To(BeNumerically("~", 10*time.Second.Milliseconds(), 2)) }) It("should HGETDEL", Label("hash", "HGETDEL"), func() { diff --git a/push/push_test.go b/push/push_test.go index 6ceadc61..69126f30 100644 --- a/push/push_test.go +++ b/push/push_test.go @@ -279,8 +279,8 @@ func TestRegistry(t *testing.T) { t.Error("UnregisterHandler should error for protected handler") } - if !strings.Contains(err.Error(), "cannot unregister protected handler") { - t.Errorf("Error message should mention protected handler, got: %v", err) + if !strings.Contains(err.Error(), "handler is protected") { + t.Errorf("Error message should mention handler is protected, got: %v", err) } // Handler should still be there @@ -491,7 +491,7 @@ func TestVoidProcessor(t *testing.T) { t.Error("VoidProcessor RegisterHandler should return error") } - if !strings.Contains(err.Error(), "cannot register push notification handler") { + if !strings.Contains(err.Error(), "register failed") { t.Errorf("Error message should mention registration failure, got: %v", err) } @@ -508,7 +508,7 @@ func TestVoidProcessor(t *testing.T) { t.Error("VoidProcessor UnregisterHandler should return error") } - if !strings.Contains(err.Error(), "cannot unregister push notification handler") { + if !strings.Contains(err.Error(), "unregister failed") { t.Errorf("Error message should mention unregistration failure, got: %v", err) } }) @@ -1466,7 +1466,7 @@ func TestErrors(t *testing.T) { t.Error("ErrHandlerExists should not return nil") } - expectedMsg := "cannot overwrite existing handler for push notification: TEST_NOTIFICATION" + expectedMsg := "handler register failed for 'TEST_NOTIFICATION': cannot overwrite existing handler" if err.Error() != expectedMsg { t.Errorf("ErrHandlerExists message should be '%s', got: %s", expectedMsg, err.Error()) } @@ -1480,7 +1480,7 @@ func TestErrors(t *testing.T) { t.Error("ErrProtectedHandler should not return nil") } - expectedMsg := "cannot unregister protected handler for push notification: PROTECTED_NOTIFICATION" + expectedMsg := "handler unregister failed for 'PROTECTED_NOTIFICATION': handler is protected" if err.Error() != expectedMsg { t.Errorf("ErrProtectedHandler message should be '%s', got: %s", expectedMsg, err.Error()) } @@ -1494,7 +1494,7 @@ func TestErrors(t *testing.T) { t.Error("ErrVoidProcessorRegister should not return nil") } - expectedMsg := "cannot register push notification handler 'VOID_TEST': push notifications are disabled (using void processor)" + expectedMsg := "void_processor register failed for 'VOID_TEST': push notifications are disabled" if err.Error() != expectedMsg { t.Errorf("ErrVoidProcessorRegister message should be '%s', got: %s", expectedMsg, err.Error()) } @@ -1508,7 +1508,7 @@ func TestErrors(t *testing.T) { t.Error("ErrVoidProcessorUnregister should not return nil") } - expectedMsg := "cannot unregister push notification handler 'VOID_TEST': push notifications are disabled (using void processor)" + expectedMsg := "void_processor unregister failed for 'VOID_TEST': push notifications are disabled" if err.Error() != expectedMsg { t.Errorf("ErrVoidProcessorUnregister message should be '%s', got: %s", expectedMsg, err.Error()) } diff --git a/redis.go b/redis.go index f7ee12fa..dfba1109 100644 --- a/redis.go +++ b/redis.go @@ -1103,9 +1103,9 @@ func (c *baseClient) processPushNotifications(ctx context.Context, cn *pool.Conn // Use WithReader to access the reader and process push notifications // This is critical for hitless upgrades to work properly // NOTE: almost no timeouts are set for this read, so it should not block - // longer than necessary, 50us should be plenty of time to read if there are any push notifications - // on the socket - return cn.WithReader(ctx, 50*time.Microsecond, func(rd *proto.Reader) error { + // longer than necessary, 10us should be plenty of time to read if there are any push notifications + // on the socket. Even if it was not enough time, the next read will just read the push notifications again. + return cn.WithReader(ctx, 10*time.Microsecond, func(rd *proto.Reader) error { // Create handler context with client, connection pool, and connection information handlerCtx := c.pushNotificationHandlerContext(cn) return c.pushProcessor.ProcessPendingNotifications(ctx, handlerCtx, rd)