Fix sporadic openflow/broker test failure

Looked like a possible race condition in how the test was structured: an
endpoint sees its peer got lost and likewise exits immediately before
having a chance to process events the peer had sent just before exiting.
Fix is to reverse which endpoint initiates the termination sequence so
we can be sure we see the required events.
This commit is contained in:
Jon Siwek 2019-05-03 11:16:38 -07:00
parent c640dd70cc
commit eda7610806
3 changed files with 17 additions and 20 deletions

View file

@ -55,14 +55,26 @@ event connection_established(c: connection)
OpenFlow::flow_mod(of_controller, match_rev, flow_mod);
}
global msg_count: count = 0;
function got_message()
{
++msg_count;
if ( msg_count == 6 )
terminate();
}
event OpenFlow::flow_mod_success(name: string, match: OpenFlow::ofp_match, flow_mod: OpenFlow::ofp_flow_mod, msg: string)
{
print "Flow_mod_success";
got_message();
}
event OpenFlow::flow_mod_failure(name: string, match: OpenFlow::ofp_match, flow_mod: OpenFlow::ofp_flow_mod, msg: string)
{
print "Flow_mod_failure";
got_message();
}
@TEST-END-FILE
@ -73,13 +85,6 @@ event OpenFlow::flow_mod_failure(name: string, match: OpenFlow::ofp_match, flow_
redef exit_only_after_terminate = T;
global msg_count: count = 0;
event die()
{
terminate();
}
event zeek_init()
{
Broker::subscribe("bro/openflow");
@ -96,28 +101,16 @@ event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
terminate();
}
function got_message()
{
++msg_count;
if ( msg_count >= 4 )
{
schedule 2sec { die() };
}
}
event OpenFlow::broker_flow_mod(name: string, dpid: count, match: OpenFlow::ofp_match, flow_mod: OpenFlow::ofp_flow_mod)
{
print "got flow_mod", dpid, match, flow_mod;
Broker::publish("bro/openflow", OpenFlow::flow_mod_success, name, match, flow_mod, "");
Broker::publish("bro/openflow", OpenFlow::flow_mod_failure, name, match, flow_mod, "");
got_message();
}
event OpenFlow::broker_flow_clear(name: string, dpid: count)
{
print "flow_clear", dpid;
got_message();
}
@TEST-END-FILE