diff options
Diffstat (limited to 'tests/modules')
| -rw-r--r-- | tests/modules/process/test.lua | 11 | ||||
| -rw-r--r-- | tests/modules/scheduler/test.lua | 22 | ||||
| -rw-r--r-- | tests/modules/socket/sched_tcp/echo_client.lua | 17 |
3 files changed, 28 insertions, 22 deletions
diff --git a/tests/modules/process/test.lua b/tests/modules/process/test.lua index 30a42fd99..3835272b4 100644 --- a/tests/modules/process/test.lua +++ b/tests/modules/process/test.lua @@ -25,10 +25,11 @@ function test_sched_process(t) stderr:close() count = count + 1 end - local cotasks = {} - for i = 1, 3 do - table.insert(cotasks, scheduler.co_start(_session)) - end - scheduler.co_waitexit(cotasks) + scheduler.co_group_begin("test", function () + for i = 1, 3 do + scheduler.co_start(_session) + end + end) + scheduler.co_group_wait("test") t:are_equal(count, 3) end diff --git a/tests/modules/scheduler/test.lua b/tests/modules/scheduler/test.lua index d6e090c6a..de62e47ed 100644 --- a/tests/modules/scheduler/test.lua +++ b/tests/modules/scheduler/test.lua @@ -7,11 +7,12 @@ function test_runjobs(t) t:are_equal(a, "xmake!") count = count + 1 end - local cotasks = {} - for i = 1, 100 do - table.insert(cotasks, scheduler.co_start(task, "xmake!")) - end - scheduler.co_waitexit(cotasks) + scheduler.co_group_begin("test", function () + for i = 1, 100 do + scheduler.co_start(task, "xmake!") + end + end) + scheduler.co_group_wait("test") t:are_equal(count, 100) end @@ -37,10 +38,11 @@ function test_yield(t) scheduler.co_yield() count = count + 1 end - local cotasks = {} - for i = 1, 10 do - table.insert(cotasks, scheduler.co_start(task)) - end - scheduler.co_waitexit(cotasks) + scheduler.co_group_begin("test", function () + for i = 1, 10 do + scheduler.co_start(task) + end + end) + scheduler.co_group_wait("test") t:are_equal(count, 10) end diff --git a/tests/modules/socket/sched_tcp/echo_client.lua b/tests/modules/socket/sched_tcp/echo_client.lua index acc681584..b77487090 100644 --- a/tests/modules/socket/sched_tcp/echo_client.lua +++ b/tests/modules/socket/sched_tcp/echo_client.lua @@ -42,20 +42,23 @@ function _session(addr, port) if sock then print("%s: connected!", sock) table.insert(socks, sock) - scheduler.co_start(_session_recv, sock) - scheduler.co_start(_session_send, sock) + scheduler.co_group_begin("test", function () + scheduler.co_start(_session_recv, sock) + scheduler.co_start(_session_send, sock) + end) else print("connect %s:%d failed", addr, port) end end function main(count) - local cotasks = {} count = count and tonumber(count) or 1 - for i = 1, count do - table.insert(cotasks, scheduler.co_start(_session, "127.0.0.1", 9001)) - end - scheduler.co_waitexit(cotasks) + scheduler.co_group_begin("test", function () + for i = 1, count do + scheduler.co_start(_session, "127.0.0.1", 9001) + end + end) + scheduler.co_group_wait("test") for _, sock in ipairs(socks) do sock:close() end |
