From 993e767426b8d5f7d3101ff36a2d48c84686bbc2 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sat, 2 Mar 2024 17:59:48 +0100 Subject: [PATCH] fix timer for timeouts --- tests/removeserver.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/removeserver.lua b/tests/removeserver.lua index 08b0a62..10928c2 100644 --- a/tests/removeserver.lua +++ b/tests/removeserver.lua @@ -9,6 +9,15 @@ local wskt = socket.bind("*", 0) local whost, wport = wskt:getsockname() wport = tonumber(wport) +-- set up a timeout to not hang on failure +local timeout_timer = copas.timer.new { + delay = 10, + callback = function() + print("timeout!") + os.exit(1) + end +} + local connection_handler = function(cskt) print(tostring(cskt).." ("..type(cskt)..") received a connection") local data, _, partial = cskt:receive() @@ -38,13 +47,7 @@ copas.addthread(function() trigger_it(i) copas.pause(0.1) end -end) - --- set up a timeout to not hang on failure -copas.addthread(function() - copas.pause(10) - print("timeout!") - os.exit(1) + timeout_timer:cancel() end) copas.loop()