summaryrefslogtreecommitdiff
path: root/tests/modules/scheduler/test.lua
blob: f794c8a3e4737c6d6a2f684cfb7b46fa17ca3c4b (plain)
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
import("core.base.scheduler")

function test_runjobs(t)

    local count = 0
    local task = function (a)
        t:are_equal(a, "xmake!")
        count = count + 1
    end
    for i = 1, 100 do
        scheduler.co_start(task, "xmake!")
    end
    scheduler.runloop()
    t:are_equal(count, 100)
end

function test_sleep(t)

    local count = 0
    local task = function (a)
        local dt = os.mclock()
        os.sleep(500)
        dt = os.mclock() - dt
        t:require(dt > 100 and dt < 1000)
        count = count + 1
    end
    for i = 1, 3 do
        scheduler.co_start(task)
    end
    scheduler.runloop()
end