Commit da5586ca authored by Dominik Charousset's avatar Dominik Charousset

Use random port for server in broker test

parent 98dbfe27
...@@ -138,31 +138,27 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) { ...@@ -138,31 +138,27 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
self->fork(peer_fun, msg.handle, buddy); self->fork(peer_fun, msg.handle, buddy);
self->quit(); self->quit();
}, },
on(atom("publish")) >> [=] {
return self->add_tcp_doorman(0, "127.0.0.1").second;
},
others() >> CAF_UNEXPECTED_MSG_CB(self) others() >> CAF_UNEXPECTED_MSG_CB(self)
}; };
} }
void run_server(bool spawn_client, const char* bin_path) { void run_server(bool spawn_client, const char* bin_path) {
auto p = spawn(pong); scoped_actor self;
uint16_t port = 4242; auto serv = io::spawn_io(peer_acceptor_fun, spawn(pong));
bool done = false; self->sync_send(serv, atom("publish")).await(
while (!done) { [&](uint16_t port) {
try { CAF_CHECKPOINT();
io::spawn_io_server(peer_acceptor_fun, port, p); cout << "server is running on port " << port << endl;
} if (spawn_client) {
catch (bind_failure&) { auto child = run_program(bin_path, "-c", port);
// try next port CAF_CHECKPOINT();
++port; child.join();
}
} }
done = true; );
}
CAF_CHECKPOINT();
cout << "server is running on port " << port << endl;
if (spawn_client) {
auto child = run_program(bin_path, "-c", port);
CAF_CHECKPOINT();
child.join();
}
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
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