From 4b127b8eed7384cca7d92ed2ce146ea17e757795 Mon Sep 17 00:00:00 2001 From: Julien Letessier Date: Thu, 15 Jan 2026 09:10:29 +0100 Subject: [PATCH] Fix pubsub SubMsg responses Attach parsed pubsub responses to SubMsg requests so message data is delivered. Adds pubsub_message_response test and runs it in test harness. --- src/ConnectConnection.cpp | 3 ++ test/pubsub_message_response.py | 56 +++++++++++++++++++++++++++++++++ test/run.sh | 4 ++- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/pubsub_message_response.py diff --git a/src/ConnectConnection.cpp b/src/ConnectConnection.cpp index 7f08ebe..086cf2b 100644 --- a/src/ConnectConnection.cpp +++ b/src/ConnectConnection.cpp @@ -185,6 +185,9 @@ void ConnectConnection::handleResponse(Handler* h) { RequestPtr req = RequestAlloc::create(mAcceptConnection); req->setType(Command::SubMsg); + ResponsePtr res = ResponseAlloc::create(); + res->set(mParser); + req->setResponse(res); mAcceptConnection->append(req); mSentRequests.push_front(req); } diff --git a/test/pubsub_message_response.py b/test/pubsub_message_response.py new file mode 100644 index 0000000..c278f1b --- /dev/null +++ b/test/pubsub_message_response.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# +# Verify pubsub message responses include message data +# + +import argparse +import sys +import redis + + +def normalize_bytes(value): + if isinstance(value, bytes): + return value.decode("utf-8") + return value + + +def run_test(host, port): + c1 = redis.StrictRedis(host=host, port=port) + c2 = redis.StrictRedis(host=host, port=port) + + ps = c1.pubsub() + ps.subscribe("ch_resp") + msg = ps.get_message(timeout=1.0) + if not msg or msg.get("type") != "subscribe": + print("FAIL: missing subscribe confirmation:", msg) + return False + + publish_result = c2.publish("ch_resp", "hello_resp") + if publish_result < 1: + print("FAIL: publish did not reach subscribers:", publish_result) + return False + + msg = ps.get_message(timeout=1.0) + if not msg or msg.get("type") != "message": + print("FAIL: missing message response:", msg) + return False + + data = normalize_bytes(msg.get("data")) + if data != "hello_resp": + print("FAIL: unexpected message data:", msg) + return False + + return True + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(conflict_handler='resolve', description="Pubsub message response test") + parser.add_argument("-h", "--host", default="127.0.0.1") + parser.add_argument("-p", "--port", type=int, default=7617) + args = parser.parse_args() + + if run_test(args.host, args.port): + print("PASS: pubsub message response") + sys.exit(0) + print("FAIL: pubsub message response") + sys.exit(1) diff --git a/test/run.sh b/test/run.sh index dcc6c05..216b171 100755 --- a/test/run.sh +++ b/test/run.sh @@ -59,11 +59,13 @@ BASIC_EXIT=0 PUBSUB_REDIS_EXIT=0 PUBSUB_MINIMAL_EXIT=0 PUBSUB_EXIT=0 +PUBSUB_MESSAGE_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=$? +uv run python3 test/pubsub_message_response.py -p 7617 || PUBSUB_MESSAGE_EXIT=$? -TEST_EXIT=$((BASIC_EXIT + PUBSUB_REDIS_EXIT + PUBSUB_MINIMAL_EXIT + PUBSUB_EXIT)) +TEST_EXIT=$((BASIC_EXIT + PUBSUB_REDIS_EXIT + PUBSUB_MINIMAL_EXIT + PUBSUB_EXIT + PUBSUB_MESSAGE_EXIT)) exit $TEST_EXIT