mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
btest/cluster/websocket: Move no-subscriptions test
...and also add one for broker.
This commit is contained in:
parent
2cd2a2b8a6
commit
43a1bab960
10 changed files with 148 additions and 15 deletions
|
@ -0,0 +1,33 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
got ping, 1, 1
|
||||
got ping, 2, 2
|
||||
got ping, 3, 3
|
||||
got ping, 4, 4
|
||||
got ping, 5, 5
|
||||
got ping, 6, 6
|
||||
got ping, 7, 7
|
||||
got ping, 8, 8
|
||||
got ping, 9, 9
|
||||
got ping, 10, 10
|
||||
got ping, 11, 11
|
||||
got ping, 12, 12
|
||||
got ping, 13, 13
|
||||
got ping, 14, 14
|
||||
got ping, 15, 15
|
||||
got ping, 16, 16
|
||||
got ping, 17, 17
|
||||
got ping, 18, 18
|
||||
got ping, 19, 19
|
||||
got ping, 20, 20
|
||||
got ping, 21, 21
|
||||
got ping, 22, 22
|
||||
got ping, 23, 23
|
||||
got ping, 24, 24
|
||||
got ping, 25, 25
|
||||
got ping, 26, 26
|
||||
got ping, 27, 27
|
||||
got ping, 28, 28
|
||||
got ping, 29, 29
|
||||
got ping, 30, 30
|
||||
got ping, 31, 31
|
||||
got ping, 32, 32
|
|
@ -1,3 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
Cluster::websocket_client_added, []
|
||||
got ping, 42
|
|
@ -0,0 +1 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
received termination signal
|
|
@ -0,0 +1,33 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
got ping, 1, 1
|
||||
got ping, 2, 2
|
||||
got ping, 3, 3
|
||||
got ping, 4, 4
|
||||
got ping, 5, 5
|
||||
got ping, 6, 6
|
||||
got ping, 7, 7
|
||||
got ping, 8, 8
|
||||
got ping, 9, 9
|
||||
got ping, 10, 10
|
||||
got ping, 11, 11
|
||||
got ping, 12, 12
|
||||
got ping, 13, 13
|
||||
got ping, 14, 14
|
||||
got ping, 15, 15
|
||||
got ping, 16, 16
|
||||
got ping, 17, 17
|
||||
got ping, 18, 18
|
||||
got ping, 19, 19
|
||||
got ping, 20, 20
|
||||
got ping, 21, 21
|
||||
got ping, 22, 22
|
||||
got ping, 23, 23
|
||||
got ping, 24, 24
|
||||
got ping, 25, 25
|
||||
got ping, 26, 26
|
||||
got ping, 27, 27
|
||||
got ping, 28, 28
|
||||
got ping, 29, 29
|
||||
got ping, 30, 30
|
||||
got ping, 31, 31
|
||||
got ping, 32, 32
|
66
testing/btest/cluster/websocket/broker/no-subscriptions.zeek
Normal file
66
testing/btest/cluster/websocket/broker/no-subscriptions.zeek
Normal file
|
@ -0,0 +1,66 @@
|
|||
# @TEST-DOC: Test that publishing events to a WebSocket client's auto topic works.
|
||||
#
|
||||
# @TEST-REQUIRES: python3 -c 'import websockets.sync'
|
||||
#
|
||||
# @TEST-PORT: BROKER_PORT1
|
||||
# @TEST-PORT: WEBSOCKET_PORT
|
||||
#
|
||||
# @TEST-EXEC: cp $FILES/ws/wstest.py .
|
||||
#
|
||||
# @TEST-EXEC: zeek -b --parse-only manager.zeek
|
||||
# @TEST-EXEC: python3 -m py_compile client.py
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=manager zeek -b ../manager.zeek"
|
||||
# @TEST-EXEC: btest-bg-run client "python3 ../client.py"
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
# @TEST-EXEC: btest-diff ./manager/.stdout
|
||||
# @TEST-EXEC: btest-diff ./manager/.stderr
|
||||
# @TEST-EXEC: btest-diff ./client/.stdout
|
||||
# @TEST-EXEC: btest-diff ./client/.stderr
|
||||
|
||||
# @TEST-START-FILE cluster-layout.zeek
|
||||
redef Cluster::nodes = {
|
||||
["manager"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
|
||||
};
|
||||
# @TEST-END-FILE
|
||||
#
|
||||
# @TEST-START-FILE manager.zeek
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
redef Log::enable_local_logging = T;
|
||||
redef Log::default_rotation_interval = 0sec;
|
||||
redef Broker::disable_ssl = T;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
global ping_count = 0;
|
||||
const ping_count_expected = 32;
|
||||
|
||||
event ping(c: count) &is_used
|
||||
{
|
||||
++ping_count;
|
||||
print "got ping", c, ping_count;
|
||||
if ( ping_count == ping_count_expected )
|
||||
terminate();
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
||||
# @TEST-START-FILE client.py
|
||||
import wstest
|
||||
|
||||
def run(ws_url):
|
||||
for i in range(32):
|
||||
with wstest.connect("ws1", ws_url) as tc:
|
||||
tc.send_json([]) # Send no subscriptions
|
||||
ack = tc.recv_json()
|
||||
assert ack.get("type") == "ack", f"{ack}"
|
||||
tc.send_json(wstest.build_event_v1("/test/pings/", "ping", [i + 1]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
wstest.main(run, wstest.WS4_URL_V1)
|
||||
# @TEST-END-FILE
|
|
@ -36,28 +36,28 @@ event zeek_init()
|
|||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
global ping_count = 0;
|
||||
const ping_count_expected = 32;
|
||||
|
||||
event ping(c: count) &is_used
|
||||
{
|
||||
print "got ping", c;
|
||||
++ping_count;
|
||||
print "got ping", c, ping_count;
|
||||
if ( ping_count == ping_count_expected )
|
||||
terminate();
|
||||
}
|
||||
|
||||
event Cluster::websocket_client_added(info: Cluster::EndpointInfo, subscriptions: string_vec)
|
||||
{
|
||||
print "Cluster::websocket_client_added", subscriptions;
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
||||
|
||||
# @TEST-START-FILE client.py
|
||||
import wstest
|
||||
|
||||
def run(ws_url):
|
||||
for i in range(32):
|
||||
with wstest.connect("ws1", ws_url) as tc:
|
||||
tc.send_json([]) # Send no subscriptions
|
||||
ack = tc.recv_json()
|
||||
assert ack.get("type") == "ack", f"{ack}"
|
||||
tc.send_json(wstest.build_event_v1("/test/pings/", "ping", [42]))
|
||||
tc.send_json(wstest.build_event_v1("/test/pings/", "ping", [i + 1]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
wstest.main(run, wstest.WS4_URL_V1)
|
Loading…
Add table
Add a link
Reference in a new issue