|
32 | 32 | #include "Utils/System.hpp" |
33 | 33 | #include "Utils/UserTuple.hpp" |
34 | 34 |
|
35 | | -#include "../src/Client/LibevNetProvider.hpp" |
36 | 35 | #include "../src/Client/Connector.hpp" |
| 36 | +#include "../src/Client/LibevNetProvider.hpp" |
| 37 | + |
| 38 | +#include <thread> |
37 | 39 |
|
38 | 40 | const char *localhost = "127.0.0.1"; |
39 | 41 | int port = 3301; |
@@ -1144,6 +1146,11 @@ response_decoding(Connector<BUFFER, NetProvider> &client) |
1144 | 1146 | client.close(conn); |
1145 | 1147 | } |
1146 | 1148 |
|
| 1149 | +void sigusr_handler(int signo) |
| 1150 | +{ |
| 1151 | + fail_unless(signo != SIGINT); |
| 1152 | +} |
| 1153 | + |
1147 | 1154 | /** Checks all available `wait` methods of connector. */ |
1148 | 1155 | template <class BUFFER, class NetProvider> |
1149 | 1156 | void |
@@ -1324,6 +1331,30 @@ test_wait(Connector<BUFFER, NetProvider> &client) |
1324 | 1331 | fail_unless(result.header.sync == static_cast<int>(f1)); |
1325 | 1332 | fail_unless(result.header.code == 0); |
1326 | 1333 |
|
| 1334 | +#ifdef __linux__ |
| 1335 | + TEST_CASE("waitAny internal wait failure (gh-121)"); |
| 1336 | + static constexpr double LONG_SLEEP_TIME = 2; |
| 1337 | + f = conn.call("remote_sleep", std::forward_as_tuple(LONG_SLEEP_TIME)); |
| 1338 | + fail_unless(!conn.futureIsReady(f)); |
| 1339 | + pthread_t tid = pthread_self(); |
| 1340 | + struct sigaction act; |
| 1341 | + act.sa_handler = sigusr_handler; |
| 1342 | + act.sa_flags = 0; |
| 1343 | + sigemptyset(&act.sa_mask); |
| 1344 | + sigaction(SIGUSR1, &act, nullptr); |
| 1345 | + auto &&signal_thread = std::thread([tid] { |
| 1346 | + sleep(LONG_SLEEP_TIME / 2); |
| 1347 | + pthread_kill(tid, SIGUSR1); |
| 1348 | + }); |
| 1349 | + fail_unless(!client.waitAny().has_value()); |
| 1350 | + fail_unless(client.waitAny().has_value()); |
| 1351 | + fail_unless(conn.futureIsReady(f)); |
| 1352 | + response = conn.getResponse(f); |
| 1353 | + fail_unless(response.has_value()); |
| 1354 | + signal_thread.join(); |
| 1355 | + sigaction(SIGUSR1, nullptr, nullptr); |
| 1356 | +#endif /* __linux__ */ |
| 1357 | + |
1327 | 1358 | client.close(conn); |
1328 | 1359 | } |
1329 | 1360 |
|
|
0 commit comments