From: Michael Wallner Date: Tue, 29 Sep 2020 09:35:52 +0000 (+0200) Subject: testing: ensure the server is properly listening X-Git-Tag: 1.1.0-beta1~236^2~39 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=12db645b4866a01c7c2bd0baba3be221e8d16ae9;p=m6w6%2Flibmemcached testing: ensure the server is properly listening --- diff --git a/test/lib/Server.cpp b/test/lib/Server.cpp index 0c99009b..8666b690 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 @@ -142,6 +142,19 @@ bool Server::isListening() { 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; diff --git a/test/lib/Server.hpp b/test/lib/Server.hpp index 44fd5e99..f37c79a5 100644 --- a/test/lib/Server.hpp +++ b/test/lib/Server.hpp @@ -59,6 +59,7 @@ public: bool signal(int signo = SIGTERM); bool check(); bool isListening(); + bool ensureListening(); bool wait(int flags = 0); bool tryWait(); diff --git a/test/tests/bin/memcat.cpp b/test/tests/bin/memcat.cpp index dfc5ddb9..4e91617e 100644 --- a/test/tests/bin/memcat.cpp +++ b/test/tests/bin/memcat.cpp @@ -32,8 +32,7 @@ TEST_CASE("bin/memcat") { MemcachedPtr memc; LoneReturnMatcher test{*memc}; - server.start(); - Retry{[&server] { return server.isListening(); }}(); + REQUIRE(server.ensureListening()); auto port = get(server.getSocketOrPort()); auto comm = "memcat --servers=localhost:" + to_string(port) + " "; diff --git a/test/tests/bin/memcp.cpp b/test/tests/bin/memcp.cpp index bbf796a6..ef234cbe 100644 --- a/test/tests/bin/memcp.cpp +++ b/test/tests/bin/memcp.cpp @@ -32,8 +32,7 @@ TEST_CASE("bin/memcp") { MemcachedPtr memc; LoneReturnMatcher test{*memc}; - server.start(); - Retry{[&server] { return server.isListening(); }}(); + REQUIRE(server.ensureListening()); auto port = get(server.getSocketOrPort()); auto comm = "memcp --servers=localhost:" + to_string(port) + " "; diff --git a/test/tests/bin/memdump.cpp b/test/tests/bin/memdump.cpp index 8e4d4537..b2caa3d1 100644 --- a/test/tests/bin/memdump.cpp +++ b/test/tests/bin/memdump.cpp @@ -32,8 +32,7 @@ TEST_CASE("bin/memdump") { MemcachedPtr memc; LoneReturnMatcher test{*memc}; - server.start(); - Retry{[&server] { return server.isListening(); }}(); + REQUIRE(server.ensureListening()); auto port = get(server.getSocketOrPort()); auto comm = "memdump --servers=localhost:" + to_string(port) + " "; diff --git a/test/tests/bin/memexist.cpp b/test/tests/bin/memexist.cpp index 36d69c4f..994727d4 100644 --- a/test/tests/bin/memexist.cpp +++ b/test/tests/bin/memexist.cpp @@ -32,8 +32,7 @@ TEST_CASE("bin/memexist") { MemcachedPtr memc; LoneReturnMatcher test{*memc}; - server.start(); - Retry{[&server] { return server.isListening(); }}(); + REQUIRE(server.ensureListening()); auto port = get(server.getSocketOrPort()); auto comm = "memexist --servers=localhost:" + to_string(port) + " "; diff --git a/test/tests/bin/memflush.cpp b/test/tests/bin/memflush.cpp index 27083c24..45246fa0 100644 --- a/test/tests/bin/memflush.cpp +++ b/test/tests/bin/memflush.cpp @@ -32,8 +32,7 @@ TEST_CASE("bin/memflush") { MemcachedPtr memc; LoneReturnMatcher test{*memc}; - server.start(); - Retry{[&server] { return server.isListening(); }}(); + REQUIRE(server.ensureListening()); auto port = get(server.getSocketOrPort()); auto comm = "memflush --servers=localhost:" + to_string(port) + " ";