|
2 | 2 | #include <gmock/gmock.h>
|
3 | 3 | #include <zmq.hpp>
|
4 | 4 |
|
| 5 | +#ifdef ZMQ_CPP11 |
| 6 | +#include <thread> |
| 7 | +#endif |
| 8 | + |
5 | 9 | class mock_monitor_t : public zmq::monitor_t
|
6 | 10 | {
|
7 | 11 | public:
|
@@ -40,3 +44,39 @@ TEST(monitor, init_check)
|
40 | 44 | while (monitor.check_event(100)) {
|
41 | 45 | }
|
42 | 46 | }
|
| 47 | + |
| 48 | +#ifdef ZMQ_CPP11 |
| 49 | +TEST(monitor, init_abort) |
| 50 | +{ |
| 51 | + zmq::context_t ctx; |
| 52 | + zmq::socket_t bind_socket(ctx, zmq::socket_type::dealer); |
| 53 | + |
| 54 | + bind_socket.bind("tcp://127.0.0.1:*"); |
| 55 | + char endpoint[255]; |
| 56 | + size_t endpoint_len = sizeof(endpoint); |
| 57 | + bind_socket.getsockopt(ZMQ_LAST_ENDPOINT, &endpoint, &endpoint_len); |
| 58 | + |
| 59 | + zmq::socket_t connect_socket(ctx, zmq::socket_type::dealer); |
| 60 | + |
| 61 | + mock_monitor_t monitor; |
| 62 | + monitor.init(connect_socket, "inproc://foo"); |
| 63 | + EXPECT_CALL(monitor, on_event_connect_delayed(testing::_, testing::_)) |
| 64 | + .Times(testing::AtLeast(1)); |
| 65 | + EXPECT_CALL(monitor, on_event_connected(testing::_, testing::_)) |
| 66 | + .Times(testing::AtLeast(1)); |
| 67 | + |
| 68 | + auto thread = std::thread([&monitor] { |
| 69 | + while (monitor.check_event(-1)) { |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + connect_socket.connect(endpoint); |
| 74 | + std::this_thread::sleep_for(std::chrono::milliseconds(250)); |
| 75 | + // TODO instead of sleeping an arbitrary amount of time, we should better |
| 76 | + // wait until the expectations have met. How can this be done with |
| 77 | + // googlemock? |
| 78 | + |
| 79 | + monitor.abort(); |
| 80 | + thread.join(); |
| 81 | +} |
| 82 | +#endif |
0 commit comments