X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=test%2Flib%2FServer.cpp;h=af6e41ba63d5a1f010f3c9ca0de0aef13bd2d989;hb=e9b1c46e3490e2940ec36cfa53ffcee5945a27d2;hp=17bafe74ca8a9c96441a21456010899635cfbf81;hpb=9f262c9ea92d4869715ca6f534c80075a8310ac1;p=awesomized%2Flibmemcached diff --git a/test/lib/Server.cpp b/test/lib/Server.cpp index 17bafe74..af6e41ba 100644 --- a/test/lib/Server.cpp +++ b/test/lib/Server.cpp @@ -1,5 +1,5 @@ #include "Server.hpp" -#include "Connection.hpp" +#include "Retry.hpp" #include "ForkAndExec.hpp" #include @@ -39,11 +39,16 @@ static inline void pushArg(vector &arr, const string &arg) { optional Server::handleArg(vector &arr, const string &arg, const arg_func_t &next_arg) { pushArg(arr, arg); - if (arg == "-p" || arg == "--port") { + if (arg == "-U" || arg == "--udp-port") { + auto port = next_arg(arg); + pushArg(arr, port); + pushArg(arr, "-p"); + pushArg(arr, port); + socket_or_port = stoi(port); + return port; + } else if (arg == "-p" || arg == "--port") { auto port = next_arg(arg); pushArg(arr, port); -// pushArg(arr, "-U"); -// pushArg(arr, port); socket_or_port = stoi(port); return port; } else if (arg == "-s" || arg == "--unix-socket") { @@ -130,13 +135,31 @@ bool Server::isListening() { } Malloced stat(memcached_stat(*memc, nullptr, nullptr)); - if (!*stat || !stat->pid || stat->pid != pid) { + if (!*stat || !stat->pid || stat->pid == -1) { + return false; + } + if (stat->pid != pid) { + cerr << "Another server is listening on " << socket_or_port + << " (expected pid " << pid << " found pid " << stat->pid << ")\n"; return false; } return true; } +bool Server::ensureListening() { + return Retry{[this] { + again: + start(); + if (!isListening()) { + if (tryWait()){ + goto again; + } + } + return isListening(); + }}(); +} + bool Server::stop() { if (!pid) { return true; @@ -162,8 +185,19 @@ bool Server::check() { bool Server::wait(int flags) { if (pid && pid == waitpid(pid, &status, flags)) { - if (drain().length()) { - cerr << "Ouput of " << *this << ":\n" << output << endl; + if (drain().length() && output != "Signal handled: Terminated.\n") { + cerr << "Output of " << *this << ":\n"; + + istringstream iss{output}; + string line; + + while (getline(iss, line)) { + cerr << " " << line << "\n"; + } + + if (output.back() != '\n') { + cerr << endl; + } output.clear(); } pid = 0;