Speed up test startup

The VM connectivity and log truncation is now done in parallel.
This commit is contained in:
Markus Mäkelä
2019-04-07 19:41:38 +03:00
parent 55bb3e9250
commit 5e3af05d48
4 changed files with 31 additions and 30 deletions

View File

@ -2,6 +2,9 @@
#include <string>
#include <cstring>
#include <iostream>
#include <future>
#include <functional>
#include <algorithm>
#include "envv.h"
@ -9,36 +12,29 @@ Nodes::Nodes()
{
}
int Nodes::check_node_ssh(int node)
bool Nodes::check_node_ssh(int node)
{
int res = 0;
bool res = true;
if (ssh_node(node, (char*) "ls > /dev/null", false) != 0)
if (ssh_node(node, "ls > /dev/null", false) != 0)
{
printf("Node %d is not available\n", node);
fflush(stdout);
res = 1;
}
else
{
fflush(stdout);
std::cout << "Node " << node << " is not available" << std::endl;
res = false;
}
return res;
}
int Nodes::check_nodes()
bool Nodes::check_nodes()
{
std::cout << "Checking nodes..." << std::endl;
std::vector<std::future<bool>> f;
for (int i = 0; i < N; i++)
{
if (check_node_ssh(i) != 0)
{
return 1;
}
f.push_back(std::async(std::launch::async, &Nodes::check_node_ssh, this, i));
}
return 0;
return std::all_of(f.begin(), f.end(), std::mem_fn(&std::future<bool>::get));
}
void Nodes::generate_ssh_cmd(char* cmd, int node, const char* ssh, bool sudo)