The tests used a 3000 ms ioloop timeout as a watchdog for the pump to
finish. The ioloop compensates for time moving forwards only while it is
waiting, not while timeout and IO callbacks are running. When the wall
clock jumps forwards during that window, or the process doesn't get
scheduled, every timeout that became due is called in the same run, so the
watchdog fires before the pump has had the chance to make any progress.
Use a 30 second watchdog instead, so that only a machine that is stalled
that long can trigger it. Keep alarm() a bit above the watchdog, so that it
still only triggers when the ioloop itself is stuck.
#include <sys/types.h>
#include <sys/socket.h>
+/* Timeout for waiting for the pump to finish. Reaching this timeout means the
+ test failed, so it just needs to be long enough that a heavily loaded or
+ stalled machine doesn't reach it before the pump has had the chance to
+ finish. */
+#define PUMP_TIMEOUT_MSECS (30*1000)
+
struct nonblock_ctx {
struct istream *in;
struct ostream *out;
iostream_pump_set_completion_callback(pump, completed, counter);
iostream_pump_start(pump);
- alarm(5);
- struct timeout *to = timeout_add(3000, failed, counter);
+ alarm(PUMP_TIMEOUT_MSECS/1000 + 5);
+ struct timeout *to = timeout_add(PUMP_TIMEOUT_MSECS, failed, counter);
io_loop_run(current_ioloop);