1
0
mirror of https://github.com/redis/go-redis.git synced 2025-09-05 20:24:00 +03:00

fix(push): fix tests

This commit is contained in:
Nedyalko Dyakov
2025-07-16 20:45:45 +03:00
parent 11ecbaf87b
commit 409dac11cf
3 changed files with 13 additions and 12 deletions

View File

@@ -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() {

View File

@@ -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())
}

View File

@@ -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)