X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=testing%2Flib%2FServer.hpp;h=ac05eb1304a062281f06388602b607e4cb07160f;hb=004d7eb1e658759b4d30932f414ed2de9a134519;hp=08ab57734ef28a1512c723c1d157ca29a2b96460;hpb=f33fd6e7d1df8e5878ce5c5605f64bab7b02ceb6;p=awesomized%2Flibmemcached diff --git a/testing/lib/Server.hpp b/testing/lib/Server.hpp index 08ab5773..ac05eb13 100644 --- a/testing/lib/Server.hpp +++ b/testing/lib/Server.hpp @@ -15,25 +15,44 @@ public: using argv_t = vector>; explicit - Server(string &&binary_, argv_t && args_ = {}); + Server(string binary_ = "false", argv_t args_ = {}); ~Server(); Server(const Server &s); Server &operator = (const Server &s); - Server &operator = (Server &&s) = default; - Server(Server &&s) = default; + Server(Server &&s) { + *this = move(s); + }; + Server &operator = (Server &&s) { + binary = exchange(s.binary, "false"); + args = exchange(s.args, {}); + pid = exchange(s.pid, 0); + pipe = exchange(s.pipe, -1); + status = exchange(s.status, 0); + signalled = exchange(s.signalled, {}); + socket_or_port = exchange(s.socket_or_port, {}); + output = exchange(s.output, {}); + return *this; + }; pid_t getPid() const; - + int getPipe() const; const string &getBinary() const; - const argv_t &getArgs() const; - const socket_or_port_t &getSocketOrPort() const; - optional start(); + struct ChildProc { + pid_t pid; + int pipe; + ChildProc(pid_t pid_, int pipe_) + : pid{pid_} + , pipe{pipe_} + { + } + }; + optional start(); bool stop(); bool signal(int signo = SIGTERM); @@ -42,16 +61,35 @@ public: bool wait(int flags = 0); bool tryWait(); + string &drain(); + private: string binary; argv_t args; + bool sasl = false; pid_t pid = 0; + int pipe = -1; int status = 0; unordered_map signalled; socket_or_port_t socket_or_port = 11211; + string output; [[nodiscard]] vector createArgv(); optional handleArg(vector &arr, const string &arg, const arg_func_t &next_arg); }; + +inline ostream &operator << (ostream &out, const socket_or_port_t sop) { + if (holds_alternative(sop)) { + out << get(sop); + } else { + out << ":" << get(sop); + } + return out; +} + +inline ostream &operator << (ostream &out, const Server &server) { + out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() << ",conn=" << server.getSocketOrPort() << "}"; + return out; +}