zeek/testing/btest/supervisor/restart.zeek
Jon Siwek 4fbcca04e8 Improve btest timeouts
* Generally increase timeouts for tests that have recent transient
  failures

* Change any test that relied on `btest-bg-wait -k` since that's never
  going to play with with CI systems.  Instead, we always need to have
  a well-defined termination condition in the test itself (and most
  already did, so didn't really need the `-k` flag anyway).
2020-02-06 17:50:17 -08:00

66 lines
1.3 KiB
Text

# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT
# @TEST-EXEC: btest-bg-wait 30
# @TEST-EXEC: btest-diff zeek/.stdout
# So the supervised node doesn't terminate right away.
redef exit_only_after_terminate=T;
global node_pid: int = 0;
global status_count = 0;
global check_interval = 0.1sec;
event check_status(name: string &default="")
{
local s = Supervisor::status(name);
local ns = s$nodes["grault"];
if ( ! ns?$pid )
{
schedule check_interval { check_status() };
return;
}
if ( status_count > 0 && node_pid == ns$pid )
{
schedule check_interval { check_status() };
return;
}
print "got supervised node status", ns$node$name;
node_pid = ns$pid;
++status_count;
if ( status_count == 1 )
{
Supervisor::restart();
schedule check_interval { check_status() };
}
else if ( status_count == 2 )
{
Supervisor::restart("grault");
schedule check_interval { check_status("grault") };
}
else
terminate();
}
event zeek_init()
{
if ( Supervisor::is_supervisor() )
{
local sn = Supervisor::NodeConfig($name="grault");
local res = Supervisor::create(sn);
if ( res != "" )
print "failed to create node", res;
sn$name = "qux";
res = Supervisor::create(sn);
if ( res != "" )
print "failed to create node", res;
event check_status();
}
}