Wait for a number of monitor intervals in tests
The tests can now wait for a number of monitor intervals. This removes the need to have hard-coded sleeps in the code and makes monitor tests more robust under heavier load.
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
#include "maxscales.h"
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
Maxscales::Maxscales(const char *pref, const char *test_cwd, bool verbose)
|
||||
{
|
||||
@ -431,3 +433,56 @@ int Maxscales::port(enum service type, int m) const
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user