-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathtimeout_errors.lua
50 lines (36 loc) · 1.1 KB
/
timeout_errors.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- Tests Copas timeout mnechanism, when a timeout handler errors out
--
-- Run the test file, it should exit successfully without hanging.
-- make sure we are pointing to the local copas first
package.path = string.format("../src/?.lua;%s", package.path)
local copas = require("copas")
local tests = {}
function tests.error_on_timeout()
local err_received
copas.addthread(function()
copas.setErrorHandler(function(err, coro, skt)
err_received = err
end, true)
print "setting timeout in 0.1 seconds"
copas.timeout(0.1, function()
print "throwing an error now..."
error("oops...")
end)
print "going to sleep for 1 second"
copas.pause(1)
if not (err_received or ""):find("oops...", 1, true) then
print("expected to find the error string 'oops...', but got: " .. tostring(err_received))
os.exit(1)
end
end)
copas.loop()
end
-- test "framework"
for name, test in pairs(tests) do
print("testing: "..tostring(name))
local status, err = pcall(test)
if not status then
error(err)
end
end
print("[✓] all tests completed successuly")