cluster/serializer/broker: Fix handler lookup

Handler overwrites operator bool, so need to explicitly test for nullptr
rather than not having any handlers defined.
This commit is contained in:
Arne Welzel 2025-01-10 18:03:35 +01:00
parent 24ee115bbc
commit 6d1259423e
6 changed files with 76 additions and 1 deletions

View file

@ -76,7 +76,7 @@ std::optional<detail::Event> to_zeek_event(const broker::zeek::Event& ev) {
zeek::Args vl; zeek::Args vl;
zeek::EventHandlerPtr handler = zeek::event_registry->Lookup(name); zeek::EventHandlerPtr handler = zeek::event_registry->Lookup(name);
if ( ! handler ) { if ( handler == nullptr ) {
zeek::reporter->Error("Failed to lookup handler for '%s'", std::string(name).c_str()); zeek::reporter->Error("Failed to lookup handler for '%s'", std::string(name).c_str());
return std::nullopt; return std::nullopt;
} }

View file

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

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
node_up, worker-1
node_down, worker-1

View file

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

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
got finish

View file

@ -0,0 +1,66 @@
# @TEST-DOC: A worker receiving an event without a handler implemented would produce a reporter error
#
# @TEST-REQUIRES: have-zeromq
#
# @TEST-GROUP: cluster-zeromq
#
# @TEST-PORT: XPUB_PORT
# @TEST-PORT: XSUB_PORT
# @TEST-PORT: LOG_PULL_PORT
#
# @TEST-EXEC: cp $FILES/zeromq/cluster-layout-simple.zeek cluster-layout.zeek
# @TEST-EXEC: cp $FILES/zeromq/test-bootstrap.zeek zeromq-test-bootstrap.zeek
#
# @TEST-EXEC: zeek --parse-only manager.zeek worker.zeek
#
# @TEST-EXEC: btest-bg-run manager "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=manager zeek -b ../manager.zeek >out"
# @TEST-EXEC: btest-bg-run worker "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=worker-1 zeek -b ../worker.zeek >out"
#
# @TEST-EXEC: btest-bg-wait 30
# @TEST-EXEC: btest-diff ./manager/out
# @TEST-EXEC: btest-diff ./manager/.stderr
# @TEST-EXEC: btest-diff ./worker/out
# @TEST-EXEC: btest-diff ./worker/.stderr
# @TEST-START-FILE common.zeek
@load ./zeromq-test-bootstrap
global hello: event() &is_used;
global finish: event() &is_used;
# @TEST-END-FILE
# @TEST-START-FILE manager.zeek
@load ./common.zeek
event send_finish(id: string)
{
Cluster::publish(Cluster::nodeid_topic(id), finish);
}
# If a node comes up that isn't us, send it a hello and
# schedule sending a my_finish
event Cluster::node_up(name: string, id: string)
{
print "node_up", name;
Cluster::publish(Cluster::nodeid_topic(id), hello);
schedule 20msec { send_finish(id) };
}
# If the worker vanishes, finish the test.
event Cluster::node_down(name: string, id: string)
{
print "node_down", name;
terminate();
}
# @TEST-END-FILE
# @TEST-START-FILE worker.zeek
@load ./common.zeek
# The worker does not implement hello!
event finish()
{
print "got finish";
terminate();
}
# @TEST-END-FILE