Add cluster_started restart tests.

This commit is contained in:
Jan Grashoefer 2023-04-21 18:36:46 +02:00
parent 2dcca004d3
commit 893d31e1aa
11 changed files with 287 additions and 0 deletions

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), manager
node fully connected (resending: F)
node fully connected (resending: T)
node fully connected (resending: T)
node fully connected (resending: T)
supervised node zeek_done(), manager

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), proxy-1
node fully connected (resending: F)
cluster_started
node fully connected (resending: T)
node fully connected (resending: T)
supervised node zeek_done(), proxy-1

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervisor zeek_init()
restarting manager
restarting manager
supervisor zeek_done()

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), worker-1
node fully connected (resending: F)
cluster_started
node fully connected (resending: T)
node fully connected (resending: T)
supervised node zeek_done(), worker-1

View file

@ -0,0 +1,10 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), manager
node fully connected
node fully connected
node fully connected
node fully connected
cluster_started
node fully connected
node fully connected
supervised node zeek_done(), manager

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), proxy-1
node fully connected
cluster_started
supervised node zeek_done(), proxy-1

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervisor zeek_init()
restarting worker-1
restarting worker-1
supervisor zeek_done()

View file

@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), worker-1
node fully connected
supervised node zeek_done(), worker-1

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
supervised node zeek_init(), worker-2
node fully connected
cluster_started
supervised node zeek_done(), worker-2

View file

@ -0,0 +1,123 @@
# @TEST-DOC: Verify cluster_started() is not rebroadcasted if the manager restarts.
# @TEST-PORT: SUPERVISOR_PORT
# @TEST-PORT: MANAGER_PORT
# @TEST-PORT: PROXY_PORT
# @TEST-PORT: WORKER1_PORT
# @TEST-PORT: WORKER2_PORT
# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT
# @TEST-EXEC: btest-bg-wait 25
# @TEST-EXEC: btest-diff zeek/supervisor.out
# @TEST-EXEC: btest-diff zeek/manager/stdout
# @TEST-EXEC: btest-diff zeek/worker-1/stdout
# @TEST-EXEC: btest-diff zeek/proxy-1/stdout
@load base/frameworks/cluster
@load policy/frameworks/cluster/experimental
# So the supervised node doesn't terminate right away.
redef exit_only_after_terminate=T;
redef Log::default_rotation_interval = 0secs;
global topic = "test-topic";
@if ( Supervisor::is_supervisor() )
global supervisor_output_file: file;
global manager_starts = 0;
event Cluster::Experimental::cluster_started()
{
# Restart the manager a first time
++manager_starts;
print supervisor_output_file, "restarting manager";
Supervisor::restart("manager");
}
global redispatched_signals = 0;
event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool)
{
if ( resending )
++redispatched_signals;
if ( redispatched_signals == 3 )
{
# Restart the manager a second time
if ( ++manager_starts >= 3 )
{
terminate();
return;
}
print supervisor_output_file, "restarting manager";
Supervisor::restart("manager");
redispatched_signals = 0;
}
}
event zeek_init()
{
Broker::subscribe(topic);
Broker::listen("127.0.0.1", to_port(getenv("SUPERVISOR_PORT")));
supervisor_output_file = open("supervisor.out");
print supervisor_output_file, "supervisor zeek_init()";
local cluster: table[string] of Supervisor::ClusterEndpoint;
cluster["manager"] = [$role=Supervisor::MANAGER, $host=127.0.0.1,
$p=to_port(getenv("MANAGER_PORT"))];
cluster["proxy-1"] = [$role=Supervisor::PROXY, $host=127.0.0.1,
$p=to_port(getenv("PROXY_PORT"))];
cluster["worker-1"] = [$role=Supervisor::WORKER, $host=127.0.0.1,
$p=to_port(getenv("WORKER1_PORT"))];
cluster["worker-2"] = [$role=Supervisor::WORKER, $host=127.0.0.1,
$p=to_port(getenv("WORKER2_PORT"))];
for ( n, ep in cluster )
{
local sn = Supervisor::NodeConfig($name = n);
sn$cluster = cluster;
sn$directory = n;
sn$stdout_file = "stdout";
sn$stderr_file = "stderr";
local res = Supervisor::create(sn);
if ( res != "" )
print fmt("failed to create node %s: %s", n, res);
}
}
event zeek_done()
{
print supervisor_output_file, "supervisor zeek_done()";
}
@else
event zeek_init()
{
print "supervised node zeek_init()", Cluster::node;
Broker::peer("127.0.0.1", to_port(getenv("SUPERVISOR_PORT")));
}
event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool)
{
print fmt("node fully connected (resending: %s)", resending);
if ( Cluster::node == "manager" )
Broker::publish(topic, Cluster::Experimental::node_fully_connected, name, id, resending);
}
event Cluster::Experimental::cluster_started()
{
print "cluster_started";
if ( Cluster::node == "manager" )
Broker::publish(topic, Cluster::Experimental::cluster_started);
}
event zeek_done()
{
print "supervised node zeek_done()", Cluster::node;
}
@endif

View file

@ -0,0 +1,109 @@
# @TEST-DOC: Verify cluster_started() is not rebroadcasted if a worker restarts.
# @TEST-PORT: SUPERVISOR_PORT
# @TEST-PORT: MANAGER_PORT
# @TEST-PORT: PROXY_PORT
# @TEST-PORT: WORKER1_PORT
# @TEST-PORT: WORKER2_PORT
# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT
# @TEST-EXEC: btest-bg-wait 25
# @TEST-EXEC: btest-diff zeek/supervisor.out
# @TEST-EXEC: btest-diff zeek/manager/stdout
# @TEST-EXEC: btest-diff zeek/worker-1/stdout
# @TEST-EXEC: btest-diff zeek/worker-2/stdout
# @TEST-EXEC: btest-diff zeek/proxy-1/stdout
@load base/frameworks/cluster
@load policy/frameworks/cluster/experimental
# So the supervised node doesn't terminate right away.
redef exit_only_after_terminate=T;
redef Log::default_rotation_interval = 0secs;
global topic = "test-topic";
@if ( Supervisor::is_supervisor() )
global supervisor_output_file: file;
global worker1_starts = 0;
event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool)
{
if ( name != "worker-1" )
return;
# Restart worker-1 twice
if ( ++worker1_starts >= 3 )
{
terminate();
return;
}
print supervisor_output_file, fmt("restarting %s", name);
Supervisor::restart("worker-1");
}
event zeek_init()
{
Broker::subscribe(topic);
Broker::listen("127.0.0.1", to_port(getenv("SUPERVISOR_PORT")));
supervisor_output_file = open("supervisor.out");
print supervisor_output_file, "supervisor zeek_init()";
local cluster: table[string] of Supervisor::ClusterEndpoint;
cluster["manager"] = [$role=Supervisor::MANAGER, $host=127.0.0.1,
$p=to_port(getenv("MANAGER_PORT"))];
cluster["proxy-1"] = [$role=Supervisor::PROXY, $host=127.0.0.1,
$p=to_port(getenv("PROXY_PORT"))];
cluster["worker-1"] = [$role=Supervisor::WORKER, $host=127.0.0.1,
$p=to_port(getenv("WORKER1_PORT"))];
cluster["worker-2"] = [$role=Supervisor::WORKER, $host=127.0.0.1,
$p=to_port(getenv("WORKER2_PORT"))];
for ( n, ep in cluster )
{
local sn = Supervisor::NodeConfig($name = n);
sn$cluster = cluster;
sn$directory = n;
sn$stdout_file = "stdout";
sn$stderr_file = "stderr";
local res = Supervisor::create(sn);
if ( res != "" )
print fmt("failed to create node %s: %s", n, res);
}
}
event zeek_done()
{
print supervisor_output_file, "supervisor zeek_done()";
}
@else
event zeek_init()
{
print "supervised node zeek_init()", Cluster::node;
Broker::peer("127.0.0.1", to_port(getenv("SUPERVISOR_PORT")));
}
event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool)
{
print "node fully connected";
if ( Cluster::node == "manager" )
Broker::publish(topic, Cluster::Experimental::node_fully_connected, name, id, resending);
}
event Cluster::Experimental::cluster_started()
{
print "cluster_started";
}
event zeek_done()
{
print "supervised node zeek_done()", Cluster::node;
}
@endif