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.
This commit is contained in:
Julien Letessier 2026-01-15 09:10:29 +01:00
parent 9117970abb
commit 4b127b8eed
3 changed files with 62 additions and 1 deletions

View File

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

View File

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

View File

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