Commit 29738cf6 authored by Dominik Charousset's avatar Dominik Charousset

count & report errors in subprocess

parent 81bbe38b
#include <thread> #include <thread>
#include <string> #include <string>
#include <cstring>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
...@@ -34,7 +35,8 @@ std::vector<string_pair> get_kv_pairs(int argc, char** argv, int begin = 1) { ...@@ -34,7 +35,8 @@ std::vector<string_pair> get_kv_pairs(int argc, char** argv, int begin = 1) {
return result; return result;
} }
void client_part(const std::vector<string_pair>& args) { int client_part(const std::vector<string_pair>& args) {
CPPA_TEST(test__remote_actor_client_part);
auto i = std::find_if(args.begin(), args.end(), auto i = std::find_if(args.begin(), args.end(),
[](const string_pair& p) { return p.first == "port"; }); [](const string_pair& p) { return p.first == "port"; });
if (i == args.end()) { if (i == args.end()) {
...@@ -69,9 +71,9 @@ void client_part(const std::vector<string_pair>& args) { ...@@ -69,9 +71,9 @@ void client_part(const std::vector<string_pair>& args) {
); );
receive ( receive (
others() >> [&] { others() >> [&] {
cerr << "unexpected message; " CPPA_ERROR("unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": " << __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()) << endl; << to_string(self->last_dequeued()));
}, },
after(std::chrono::seconds(0)) >> [&] { } after(std::chrono::seconds(0)) >> [&] { }
); );
...@@ -81,26 +83,33 @@ void client_part(const std::vector<string_pair>& args) { ...@@ -81,26 +83,33 @@ void client_part(const std::vector<string_pair>& args) {
on(atom("foo"), atom("bar"), i) >> [] { on(atom("foo"), atom("bar"), i) >> [] {
}, },
others() >> [] { others() >> [&] {
cerr << "unexpected message; " CPPA_ERROR("unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": " << __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()) << endl; << to_string(self->last_dequeued()));
}, },
after(std::chrono::seconds(10)) >> [&] { after(std::chrono::seconds(10)) >> [&] {
cerr << "unexpected timeout!" << endl; CPPA_ERROR("unexpected timeout!");
} }
); );
} }
return CPPA_TEST_RESULT;
} }
} // namespace <anonymous> } // namespace <anonymous>
int main(int argc, char** argv) { int main(int argc, char** argv) {
const char* app_path = argv[0]; cout << "argv[0] = " << argv[0] << endl;
std::string app_path = argv[0];
bool run_remote_actor = true;
if (argc > 1) { if (argc > 1) {
if (strcmp(argv[1], "run_remote_actor=false") == 0) {
run_remote_actor = false;
}
else {
auto args = get_kv_pairs(argc, argv); auto args = get_kv_pairs(argc, argv);
client_part(args); return client_part(args);
return 0; }
} }
CPPA_TEST(test__remote_actor); CPPA_TEST(test__remote_actor);
//auto ping_actor = spawn(ping, 10); //auto ping_actor = spawn(ping, 10);
...@@ -117,17 +126,23 @@ int main(int argc, char** argv) { ...@@ -117,17 +126,23 @@ int main(int argc, char** argv) {
} }
} }
while (!success); while (!success);
std::thread child;
std::ostringstream oss; std::ostringstream oss;
if (run_remote_actor) {
oss << app_path << " run=remote_actor port=" << port;// << " &>client.txt"; oss << app_path << " run=remote_actor port=" << port;// << " &>client.txt";
// execute client_part() in a separate process, // execute client_part() in a separate process,
// connected via localhost socket // connected via localhost socket
std::thread child([&oss]() { child = std::thread([&oss]() {
std::string cmdstr = oss.str(); std::string cmdstr = oss.str();
if (system(cmdstr.c_str()) != 0) { if (system(cmdstr.c_str()) != 0) {
cerr << "FATAL: command \"" << cmdstr << "\" failed!" << endl; cerr << "FATAL: command \"" << cmdstr << "\" failed!" << endl;
abort(); abort();
} }
}); });
}
else {
cout << "actor published at port " << port << endl;
}
//cout << "await SpawnPing message" << endl; //cout << "await SpawnPing message" << endl;
receive ( receive (
on(atom("SpawnPing")) >> []() { on(atom("SpawnPing")) >> []() {
...@@ -161,6 +176,6 @@ int main(int argc, char** argv) { ...@@ -161,6 +176,6 @@ int main(int argc, char** argv) {
} }
); );
// wait until separate process (in sep. thread) finished execution // wait until separate process (in sep. thread) finished execution
child.join(); if (run_remote_actor) child.join();
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment