summaryrefslogtreecommitdiff
path: root/tests/modules/process/test.lua
blob: bafd619c0c8725898bebbb3a84bfb7be3547b9fe (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
33
34
35
36
import("core.base.process")
import("core.base.scheduler")

local inftimeout = 5000

function test_single_process(t)

    local stdout = os.tmpfile()
    local stderr = os.tmpfile()
    local proc = process.openv("xmake", {"lua", "print", "xmake"}, {stdout = stdout, stderr = stderr})
    proc:wait(inftimeout)
    proc:close()
    t:are_equal(io.readfile(stdout):trim(), "xmake")
end

function test_sched_process(t)

    local count = 0
    local _session = function ()
        local stdout = io.open(os.tmpfile(), 'w')
        local stderr = io.open(os.tmpfile(), 'w')
        local proc = process.openv("xmake", {"lua", "print", "xmake"}, {stdout = stdout, stderr = stderr})
        local ok, status = proc:wait(inftimeout)
        proc:close()
        stdout:close()
        stderr:close()
        count = count + 1
    end
    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