Skip to content

Commit

Permalink
fix timer for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Mar 2, 2024
1 parent 5f29757 commit 993e767
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/removeserver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit 993e767

Please sign in to comment.