Skip to content

Commit

Permalink
Merge pull request zeromq#417 from gummif/gfa/pre-refactoring
Browse files Browse the repository at this point in the history
Problem: Warnings and duplication
  • Loading branch information
sigiesec authored May 22, 2020
2 parents a2ef92e + 76e6bac commit c4d4cf7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
23 changes: 13 additions & 10 deletions tests/active_poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,16 @@ struct server_client_setup : common_server_client_setup

zmq::event_flags events = zmq::event_flags::none;
};

const std::string hi_str = "Hi";

}

TEST_CASE("poll basic", "[active_poller]")
{
server_client_setup s;

CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));

zmq::active_poller_t active_poller;
bool message_received = false;
Expand All @@ -189,7 +192,7 @@ TEST_CASE("poll basic", "[active_poller]")
/// \todo this contains multiple test cases that should be split up
TEST_CASE("client server", "[active_poller]")
{
const std::string send_msg = "Hi";
const std::string send_msg = hi_str;

// Setup server and client
server_client_setup s;
Expand Down Expand Up @@ -258,7 +261,7 @@ TEST_CASE("remove invalid socket throws", "[active_poller]")
TEST_CASE("wait on added empty handler", "[active_poller]")
{
server_client_setup s;
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
zmq::active_poller_t active_poller;
zmq::active_poller_t::handler_type handler;
CHECK_NOTHROW(active_poller.add(s.server, zmq::event_flags::pollin, handler));
Expand Down Expand Up @@ -320,7 +323,7 @@ TEST_CASE("poll client server", "[active_poller]")
CHECK_NOTHROW(active_poller.add(s.server, zmq::event_flags::pollin, s.handler));

// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));

// wait for message and verify events
CHECK_NOTHROW(active_poller.wait(std::chrono::milliseconds{500}));
Expand Down Expand Up @@ -348,7 +351,7 @@ TEST_CASE("wait one return", "[active_poller]")
event_flags) { ++count; }));

// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));

// wait for message and verify events
CHECK(1 == active_poller.wait(std::chrono::milliseconds{500}));
Expand All @@ -358,7 +361,7 @@ TEST_CASE("wait one return", "[active_poller]")
TEST_CASE("wait on move constructed active_poller", "[active_poller]")
{
server_client_setup s;
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
zmq::active_poller_t a;
zmq::active_poller_t::handler_type handler;
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, handler));
Expand All @@ -372,7 +375,7 @@ TEST_CASE("wait on move constructed active_poller", "[active_poller]")
TEST_CASE("wait on move assigned active_poller", "[active_poller]")
{
server_client_setup s;
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
zmq::active_poller_t a;
zmq::active_poller_t::handler_type handler;
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, handler));
Expand All @@ -395,14 +398,14 @@ TEST_CASE("received on move constructed active_poller", "[active_poller]")
a.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++
count; }));
// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
// wait for message and verify it is received
CHECK(1 == a.wait(std::chrono::milliseconds{500}));
CHECK(1u == count);
// Move construct active_poller b
zmq::active_poller_t b{std::move(a)};
// client sends message again
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
// wait for message and verify it is received
CHECK(1 == b.wait(std::chrono::milliseconds{500}));
CHECK(2u == count);
Expand Down Expand Up @@ -434,7 +437,7 @@ TEST_CASE("remove from handler", "[active_poller]")
CHECK(ITER_NO == active_poller.size());
// Clients send messages
for (auto &s : setup_list) {
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
}

// Wait for all servers to receive a message
Expand Down
2 changes: 1 addition & 1 deletion tests/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST_CASE("context - use socket after shutdown", "[context]")
{
sock.connect("inproc://test");
zmq::message_t msg;
sock.recv(msg, zmq::recv_flags::dontwait);
(void)sock.recv(msg, zmq::recv_flags::dontwait);
REQUIRE(false);
}
catch (const zmq::error_t& e)
Expand Down
14 changes: 8 additions & 6 deletions tests/poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ TEST_CASE("poller remove registered non empty", "[poller]")
CHECK_NOTHROW(poller.remove(socket));
}

const std::string hi_str = "Hi";

TEST_CASE("poller poll basic", "[poller]")
{
common_server_client_setup s;

CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));

zmq::poller_t<int> poller;
std::vector<zmq::poller_event<int>> events{1};
Expand Down Expand Up @@ -245,7 +247,7 @@ TEST_CASE("poller poll client server", "[poller]")
CHECK_NOTHROW(poller.add(s.server, zmq::event_flags::pollin, &s.server));

// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));

// wait for message and verify events
std::vector<zmq::poller_event<zmq::socket_t>> events(1);
Expand All @@ -271,7 +273,7 @@ TEST_CASE("poller wait one return", "[poller]")
CHECK_NOTHROW(poller.add(s.server, zmq::event_flags::pollin));

// client sends message
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));

// wait for message and verify events
std::vector<zmq::poller_event<>> events(1);
Expand All @@ -281,7 +283,7 @@ TEST_CASE("poller wait one return", "[poller]")
TEST_CASE("poller wait on move constructed", "[poller]")
{
common_server_client_setup s;
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
zmq::poller_t<> a;
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin));
zmq::poller_t<> b{std::move(a)};
Expand All @@ -295,7 +297,7 @@ TEST_CASE("poller wait on move constructed", "[poller]")
TEST_CASE("poller wait on move assigned", "[poller]")
{
common_server_client_setup s;
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
zmq::poller_t<> a;
CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin));
zmq::poller_t<> b;
Expand Down Expand Up @@ -323,7 +325,7 @@ TEST_CASE("poller remove from handler", "[poller]")
}
// Clients send messages
for (auto &s : setup_list) {
CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none));
CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none));
}

// Wait for all servers to receive a message
Expand Down

0 comments on commit c4d4cf7

Please sign in to comment.