summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-04 23:10:47 +0800
committerruki <[email protected]>2020-02-07 22:45:56 +0800
commit7cf854042808382beff5e3ceaaa430f8369d980c (patch)
tree867e20659d3ffcf9e1a9d484a12cd2a9d65eb3b0 /tests/modules
parent9d205f5db11e184073990883e1a7b94d1d4b783b (diff)
improve co_group_begin
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/process/test.lua11
-rw-r--r--tests/modules/scheduler/test.lua22
-rw-r--r--tests/modules/socket/sched_tcp/echo_client.lua17
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