btest/websocket/terminate-while-queueing: Use ZeroMQ

This adds a helper script to start the XPUB/XSUB proxy using the
XPUB_PORT and XSUB_PORT environment variables. The crux here is
that WebSocket clients go through the central XPUB/XSUB proxy.
This is different from Broker where WebSocket clients attach via
local hubs to the endpoint which doesn't require additional
configuration.
This commit is contained in:
Arne Welzel 2025-09-24 13:21:45 +02:00
parent 8d3a62edc1
commit 2730a0dd61
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,24 @@
# Helper script expecting XPUB_PORT / XSUB_PORT environments
# and redefining the ZeroMQ options accordingly and starting
# the zmq_proxy_thread.
#
# This is primarily useful for testing of WebSocket functionality
# while the ZeroMQ backend is enabled.
@load base/utils/numbers
@load frameworks/cluster/backend/zeromq
const local_addr_str = "127.0.0.1" &redef;
redef Cluster::Backend::ZeroMQ::listen_xpub_endpoint = fmt("tcp://%s:%s", local_addr_str, port_to_count(to_port(getenv("XPUB_PORT"))));
redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = fmt("tcp://%s:%s", local_addr_str, port_to_count(to_port(getenv("XSUB_PORT"))));
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = fmt("tcp://%s:%s", local_addr_str, port_to_count(to_port(getenv("XSUB_PORT"))));
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = fmt("tcp://%s:%s", local_addr_str, port_to_count(to_port(getenv("XPUB_PORT"))));
event zeek_init() &priority=100
{
if ( ! Cluster::Backend::ZeroMQ::spawn_zmq_proxy_thread() )
Reporter::fatal("Failed to spawn ZeroMQ proxy thread");
if ( ! Cluster::init() )
Reporter::fatal("Failed to initialize ZeroMQ backend");
}

View file

@ -2,9 +2,13 @@
#
# @TEST-REQUIRES: python3 -c 'import websockets.sync'
#
# @TEST-PORT: XPUB_PORT
# @TEST-PORT: XSUB_PORT
# @TEST-PORT: WEBSOCKET_PORT
#
# @TEST-EXEC: cp $FILES/zeromq/single-node.zeek zeromq-single-node.zeek
# @TEST-EXEC: cp $FILES/ws/wstest.py .
#
# @TEST-EXEC: zeek -b --parse-only manager.zeek
# @TEST-EXEC: python3 -m py_compile client.py
#
@ -19,6 +23,8 @@
# @TEST-EXEC: btest-diff ./client/.stderr
# @TEST-START-FILE manager.zeek
@load zeromq-single-node
redef exit_only_after_terminate = T;
# Force dispatcher queue being full quickly!