Move wait_for_maxscale functionality inside MaxScale
By exposing a (currently undocumented) debug endpoint that lets one monitor interval pass, we make the reuse of the monitor waiting functionality a lot easier. With it, when MaxScale is started by the test framework it knows that at least one monitor interval will have passed for all monitors and that the system is ready to accept queries.
This commit is contained in:
@ -447,56 +447,5 @@ int Maxscales::port(enum service type, int m) const
|
||||
|
||||
void Maxscales::wait_for_monitor(int intervals, int m)
|
||||
{
|
||||
// Helper for getting number of monitor ticks
|
||||
auto get_ticks = [&](std::string name) {
|
||||
int rc;
|
||||
char* ticks = ssh_node_output_f(m,
|
||||
false,
|
||||
&rc,
|
||||
"maxctrl api get monitors/%s data.attributes.ticks",
|
||||
name.c_str());
|
||||
char* ptr;
|
||||
int rval = strtol(ticks, &ptr, 10);
|
||||
|
||||
if (ptr == ticks || (*ptr != '\0' && !isspace(*ptr)))
|
||||
{
|
||||
printf("ERROR, invalid monitor tick value: %s\n", ticks);
|
||||
rval = -1;
|
||||
}
|
||||
|
||||
free(ticks);
|
||||
return rval;
|
||||
};
|
||||
|
||||
int rc = 0;
|
||||
|
||||
// Get a list of monitor names that are running
|
||||
char* monitors = ssh_node_output_f(m, false, &rc, "maxctrl --tsv list monitors|grep Running|cut -f 1");
|
||||
std::istringstream is;
|
||||
is.str(monitors);
|
||||
free(monitors);
|
||||
std::string name;
|
||||
std::unordered_map<std::string, int> ticks;
|
||||
|
||||
// For each monitor, store the current monitor tick
|
||||
while (std::getline(is, name))
|
||||
{
|
||||
ticks[name] = get_ticks(name);
|
||||
}
|
||||
|
||||
for (auto a : ticks)
|
||||
{
|
||||
// Wait a maximum of 60 seconds for a single monitor interval
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
int start = a.second;
|
||||
int end = get_ticks(a.first);
|
||||
|
||||
if (start == -1 || end == -1 || end - start >= intervals)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
ssh_node_f(m, false, "for ((i=0;i<%d;i++)); do maxctrl api get maxscale/debug/monitor_wait; done", intervals);
|
||||
}
|
||||
|
@ -724,7 +724,8 @@ void TestConnections::init_maxscale(int m)
|
||||
"cp maxscale.cnf %s;"
|
||||
"iptables -F INPUT;"
|
||||
"rm -rf %s/*.log /tmp/core* /dev/shm/* /var/lib/maxscale/maxscale.cnf.d/ /var/lib/maxscale/*;"
|
||||
"%s",
|
||||
"%s"
|
||||
"maxctrl api get maxscale/debug/monitor_wait",
|
||||
maxscales->maxscale_cnf[m],
|
||||
maxscales->maxscale_log_dir[m],
|
||||
maxscale::start ? "service maxscale restart;" : "");
|
||||
|
Reference in New Issue
Block a user