summaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2022-03-04 13:38:36 +0000
committerHåvard Pettersen <havardpe@oath.com>2022-03-05 15:00:58 +0000
commit2681bcd99a024d0e94c2cddd08b7636818773a73 (patch)
treefe8466205ba79ea6b7ab89008247070f88cd918f /fnet
parentbeed3becc8ec1abe88aea8aa88e6e703fb67dc3c (diff)
gc old process code
also added read_line function to new Process code
Diffstat (limited to 'fnet')
-rw-r--r--fnet/src/tests/examples/examples_test.cpp249
1 files changed, 120 insertions, 129 deletions
diff --git a/fnet/src/tests/examples/examples_test.cpp b/fnet/src/tests/examples/examples_test.cpp
index dc7b051bd80..b6476311adb 100644
--- a/fnet/src/tests/examples/examples_test.cpp
+++ b/fnet/src/tests/examples/examples_test.cpp
@@ -1,6 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
-#include <vespa/vespalib/util/child_process.h>
+#include <vespa/vespalib/process/process.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/thread.h>
@@ -11,209 +11,200 @@
static const int PORT0 = 18570;
static const int PORT1 = 18571;
-using vespalib::ChildProcess;
+using vespalib::Process;
+using vespalib::make_string_short::fmt;
-bool runProc(ChildProcess &proc, std::atomic<bool> &done) {
- char buf[4_Ki];
- proc.close(); // close stdin
- while (proc.running() && !done) {
- if (!proc.eof()) {
- uint32_t res = proc.read(buf, sizeof(buf), 10);
- std::string tmp(buf, res);
- fprintf(stderr, "%s", tmp.c_str());
- }
- vespalib::Thread::sleep(10);
+int run_proc(Process &proc, vespalib::string &output) {
+ proc.close();
+ for (auto mem = proc.obtain(); mem.size > 0; mem = proc.obtain()) {
+ output.append(mem.data, mem.size);
+ proc.evict(mem.size);
}
- if (done && proc.running()) {
- kill(proc.getPid(), SIGTERM);
- return proc.wait(60000);
+ return proc.join();
+}
+
+void consume_result(Process &proc) {
+ vespalib::string output;
+ int status = run_proc(proc, output);
+ fprintf(stderr, "child output(server): >>>%s<<<\n", output.c_str());
+ if (status != 0) {
+ // Allow 'killed by SIGTERM' result status. This is needed as
+ // some clients will exit with success status even when the
+ // server is not yet running, resulting in the server being
+ // killed before it has installed any signal handlers.
+ EXPECT_TRUE(status & 0x80000000);
+ status &= 0x7fffffff;
+ EXPECT_TRUE(WIFSIGNALED(status));
+ EXPECT_EQUAL(WTERMSIG(status), SIGTERM);
}
- return !proc.failed();
}
-bool runProc(const std::string &cmd) {
- bool ok = false;
- for (size_t retry = 0; !ok && retry < 60; ++retry) {
+bool run_with_retry(const vespalib::string &cmd) {
+ for (size_t retry = 0; retry < 60; ++retry) {
if (retry > 0) {
fprintf(stderr, "retrying command in 500ms...\n");
vespalib::Thread::sleep(500);
}
- std::atomic<bool> done(false);
- ChildProcess proc(cmd.c_str());
- ok = runProc(proc, done);
+ vespalib::string output;
+ Process proc(cmd, true);
+ int status = run_proc(proc, output);
+ fprintf(stderr, "child output(client): >>>%s<<<\n", output.c_str());
+ if (status == 0) {
+ return true;
+ }
}
- return ok;
+ fprintf(stderr, "giving up...\n");
+ return false;
}
TEST("usage") {
- std::atomic<bool> done(false);
- {
- ChildProcess proc("exec ../../examples/proxy/fnet_proxy_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/ping/fnet_pingserver_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/ping/fnet_pingclient_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/fnet_rpc_client_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/fnet_rpc_server_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/fnet_echo_client_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/vespa-rpc-info");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/vespa-rpc-invoke-bin");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/fnet_rpc_callback_server_app");
- EXPECT_FALSE(runProc(proc, done));
- }
- {
- ChildProcess proc("exec ../../examples/frt/rpc/fnet_rpc_callback_client_app");
- EXPECT_FALSE(runProc(proc, done));
- }
+ EXPECT_FALSE(Process::run("exec ../../examples/proxy/fnet_proxy_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/ping/fnet_pingserver_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/ping/fnet_pingclient_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/fnet_rpc_client_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/fnet_rpc_server_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/fnet_echo_client_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/vespa-rpc-info"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/vespa-rpc-invoke-bin"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/fnet_rpc_callback_server_app"));
+ EXPECT_FALSE(Process::run("exec ../../examples/frt/rpc/fnet_rpc_callback_client_app"));
}
TEST("timeout") {
- std::string out;
- EXPECT_TRUE(ChildProcess::run("exec ../../examples/timeout/fnet_timeout_app", out));
+ vespalib::string out;
+ EXPECT_TRUE(Process::run("exec ../../examples/timeout/fnet_timeout_app", out));
fprintf(stderr, "%s\n", out.c_str());
}
-TEST_MT_F("ping", 2, std::atomic<bool>()) {
+TEST_MT_F("ping", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/ping/fnet_pingserver_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/ping/fnet_pingserver_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/ping/fnet_pingclient_app tcp/localhost:%d",
- PORT0).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/ping/fnet_pingclient_app tcp/localhost:%d",
+ PORT0)));
+ kill(f1, SIGTERM);
}
}
-TEST_MT_F("ping times out", 2, std::atomic<bool>()) {
+TEST_MT_F("ping times out", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
float timeout_s = 0.1;
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/ping/fnet_pingclient_app tcp/localhost:%d %f",
- PORT0, timeout_s).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/ping/fnet_pingclient_app tcp/localhost:%d %f",
+ PORT0, timeout_s)));
+ kill(f1, SIGTERM);
}
}
-TEST_MT_F("ping with proxy", 3, std::atomic<bool>()) {
+TEST_MT_FF("ping with proxy", 3, pid_t(-1), pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/ping/fnet_pingserver_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/ping/fnet_pingserver_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else if (thread_id == 1) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/proxy/fnet_proxy_app tcp/%d tcp/localhost:%d",
- PORT1, PORT0).c_str());
+ Process proc(fmt("exec ../../examples/proxy/fnet_proxy_app tcp/%d tcp/localhost:%d",
+ PORT1, PORT0), true);
+ f2 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/ping/fnet_pingclient_app tcp/localhost:%d",
- PORT1).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/ping/fnet_pingclient_app tcp/localhost:%d",
+ PORT1)));
+ kill(f1, SIGTERM);
+ kill(f2, SIGTERM);
}
}
-TEST_MT_F("rpc client server", 2, std::atomic<bool>()) {
+TEST_MT_F("rpc client server", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_client_app tcp/localhost:%d",
- PORT0).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/frt/rpc/fnet_rpc_client_app tcp/localhost:%d",
+ PORT0)));
+ kill(f1, SIGTERM);
}
}
-TEST_MT_F("rpc echo client", 2, std::atomic<bool>()) {
+TEST_MT_F("rpc echo client", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_echo_client_app tcp/localhost:%d",
- PORT0).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/frt/rpc/fnet_echo_client_app tcp/localhost:%d",
+ PORT0)));
+ kill(f1, SIGTERM);
}
}
-TEST_MT_F("rpc info", 2, std::atomic<bool>()) {
+TEST_MT_F("rpc info", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/frt/rpc/vespa-rpc-info tcp/localhost:%d",
- PORT0).c_str()));
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/frt/rpc/vespa-rpc-info tcp/localhost:%d verbose",
- PORT0).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/frt/rpc/vespa-rpc-info tcp/localhost:%d",
+ PORT0)));
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/frt/rpc/vespa-rpc-info tcp/localhost:%d verbose",
+ PORT0)));
+ kill(f1, SIGTERM);
}
}
-TEST_MT_F("rpc invoke", 2, std::atomic<bool>()) {
+TEST_MT_F("rpc invoke", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/frt/rpc/fnet_rpc_server_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/frt/rpc/vespa-rpc-invoke-bin tcp/localhost:%d frt.rpc.echo "
- "b:1 h:2 i:4 l:8 f:0.5 d:0.25 s:foo",
- PORT0).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/frt/rpc/vespa-rpc-invoke-bin tcp/localhost:%d frt.rpc.echo "
+ "b:1 h:2 i:4 l:8 f:0.5 d:0.25 s:foo",
+ PORT0)));
+ kill(f1, SIGTERM);
}
}
-TEST_MT_F("rpc callback client server", 2, std::atomic<bool>()) {
+TEST_MT_F("rpc callback client server", 2, pid_t(-1)) {
if (thread_id == 0) {
- ChildProcess proc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_callback_server_app tcp/%d",
- PORT0).c_str());
+ Process proc(fmt("exec ../../examples/frt/rpc/fnet_rpc_callback_server_app tcp/%d",
+ PORT0), true);
+ f1 = proc.pid();
TEST_BARRIER();
- EXPECT_TRUE(runProc(proc, f1));
+ TEST_DO(consume_result(proc));
} else {
TEST_BARRIER();
- EXPECT_TRUE(runProc(vespalib::make_string("exec ../../examples/frt/rpc/fnet_rpc_callback_client_app tcp/localhost:%d",
- PORT0).c_str()));
- f1 = true;
+ EXPECT_TRUE(run_with_retry(fmt("exec ../../examples/frt/rpc/fnet_rpc_callback_client_app tcp/localhost:%d",
+ PORT0)));
+ kill(f1, SIGTERM);
}
}
-TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }
+TEST_MAIN() { TEST_RUN_ALL(); }