From dca6079f59dfca27fd5e8d1476f107247479b037 Mon Sep 17 00:00:00 2001 From: Julien Letessier Date: Wed, 14 Jan 2026 22:34:51 +0100 Subject: [PATCH] Fix pubsub test assertions --- conf/try.conf | 5 ++- test/pubsub_minimal.py | 99 ++++++++++++++++++++++++++++++++++++++++++ test/run.sh | 6 ++- 3 files changed, 107 insertions(+), 3 deletions(-) create mode 100755 test/pubsub_minimal.py diff --git a/conf/try.conf b/conf/try.conf index ca9eb26..85df9e9 100644 --- a/conf/try.conf +++ b/conf/try.conf @@ -1,7 +1,8 @@ ## This conf is only for test -ClusterServerPool { - Servers { +StandaloneServerPool { + RefreshMethod fixed + Group test { + 127.0.0.1:6379 } } diff --git a/test/pubsub_minimal.py b/test/pubsub_minimal.py new file mode 100755 index 0000000..d6d792a --- /dev/null +++ b/test/pubsub_minimal.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# +# Minimal test to reproduce pubsub message queueing issue in Predixy +# Tests pass against Redis (6379) but fail against Predixy (7617) + +import redis +import sys +import argparse + +def test_redis(host, port): + """Test pubsub against Redis or Predixy""" + print(f"\n=== Testing against {host}:{port} ===\n") + + c1 = redis.StrictRedis(host=host, port=port) + c2 = redis.StrictRedis(host=host, port=port) + + ps = c1.pubsub() + + # Step 1: Subscribe to channel 'ch' + print("1. Subscribing to channel 'ch'...") + ps.subscribe('ch') + + # Step 2: Get subscribe confirmation + print("2. Getting subscribe confirmation...") + msg = ps.get_message(timeout=1.0) + print(f" Received: {msg}") + if msg and msg.get('type') == 'subscribe' and msg.get('channel') in (b'ch', 'ch'): + print(" ✓ Subscribe confirmation received") + else: + print(f" ✗ Expected subscribe confirmation, got: {msg}") + return False + + # Step 3: Publish a message + print("3. Publishing 'hello' to channel 'ch'...") + pub_result = c2.publish('ch', 'hello') + print(f" Publish returned: {pub_result}") + + # Step 4: Get the published message + print("4. Getting published message...") + msg = ps.get_message(timeout=1.0) + print(f" Received: {msg}") + if msg and msg.get('type') == 'message': + data = msg.get('data') + if isinstance(data, bytes): + data = data.decode('utf-8') + if data == 'hello': + print(" ✓ Published message received") + else: + print(f" ✗ Expected 'hello', got: {data}") + return False + else: + print(f" ✗ Expected message, got: {msg}") + return False + + # Step 5: Psubscribe to pattern 'ch*' + print("5. Psubscribing to pattern 'ch*'...") + ps.psubscribe('ch*') + + # Step 6: Get psubscribe confirmation (THIS FAILS WITH PREDIXY) + print("6. Getting psubscribe confirmation...") + msg = ps.get_message(timeout=1.0) + print(f" Received: {msg}") + if msg and msg.get('type') == 'psubscribe': + pattern = msg.get('channel') or msg.get('pattern') + if isinstance(pattern, bytes): + pattern = pattern.decode('utf-8') + if pattern == 'ch*': + print(" ✓ Psubscribe confirmation received") + return True + else: + print(f" ✗ Expected pattern 'ch*', got: {pattern}") + return False + else: + print(f" ✗ Expected psubscribe confirmation, got: {msg}") + print(f" This is the bug: old messages are returned instead of new ones") + return False + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Minimal pubsub test') + parser.add_argument('--host', default='127.0.0.1', help='Host (default: 127.0.0.1)') + parser.add_argument('-p', '--port', type=int, required=True, help='Port (6379 for Redis, 7617 for Predixy)') + args = parser.parse_args() + + host = args.host + port = args.port + + try: + success = test_redis(host, port) + if success: + print("\n✓ Test PASSED") + sys.exit(0) + else: + print("\n✗ Test FAILED") + sys.exit(1) + except Exception as e: + print(f"\n✗ Test ERROR: {e}") + import traceback + traceback.print_exc() + sys.exit(1) diff --git a/test/run.sh b/test/run.sh index f95b0db..dcc6c05 100755 --- a/test/run.sh +++ b/test/run.sh @@ -56,10 +56,14 @@ echo "Running tests..." cd "$PROJECT_ROOT" BASIC_EXIT=0 +PUBSUB_REDIS_EXIT=0 +PUBSUB_MINIMAL_EXIT=0 PUBSUB_EXIT=0 uv run python3 test/basic.py || BASIC_EXIT=$? +uv run python3 test/pubsub_minimal.py -p 7617 || PUBSUB_REDIS_EXIT=$? +uv run python3 test/pubsub_minimal.py -p 6379 || PUBSUB_MINIMAL_EXIT=$? uv run python3 test/pubsub.py || PUBSUB_EXIT=$? -TEST_EXIT=$((BASIC_EXIT + PUBSUB_EXIT)) +TEST_EXIT=$((BASIC_EXIT + PUBSUB_REDIS_EXIT + PUBSUB_MINIMAL_EXIT + PUBSUB_EXIT)) exit $TEST_EXIT