Commit e0680908 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia
Browse files

Teste de status de job com proc. terminados no driver POSIX.

[SOMA-6857][SOMA-7152]
parent 3dfed78e
local copas = require "copas" local copas = require "copas"
local module = require "sga.driver.pbs" local module = require "sga.driver.pbs"
local utils = require "test.driver.utils"
local tmpdir = os.tmpname()
os.remove(tmpdir)
lfs.mkdir(tmpdir)
local function expectCommand(delay, output, cmd, ...)
local argPath = tmpdir.."/"..cmd..".out"
local cmdPath = "./"..cmd
local file = assert(io.open(cmdPath, "w"))
file:write([[
#!/bin/bash
function expect {
if [ "$2" != "$3" ]
then
echo -n "']]..cmd..[['argument #$1 expected to be '$3', but was '$2'" >> ]]..argPath..[[;
exit 1;
fi
}
]])
for i = 1, select("#", ...) do
local value = select(i, ...)
assert(type(value) == "string")
file:write(string.format('expect %d "$%d" %q\n', i, i, value))
end
file:write(string.format('sleep %d\n', delay))
file:write(string.format('echo %q\n', output))
file:write(string.format('echo -n "$@" >> %s\n', argPath))
file:close()
os.execute("chmod 700 "..cmdPath)
local expected = string.format(table.concat({ ... }, " "))
return function ()
local file = assert(io.open(argPath))
local args = file:read("*a")
file:close()
os.remove(argPath)
os.remove(cmdPath)
assert.equal(expected, args)
end
end
local threadErrors = {} local threadErrors = {}
...@@ -74,7 +33,7 @@ describe("SGA driver for PBS", function() ...@@ -74,7 +33,7 @@ describe("SGA driver for PBS", function()
it("should not block the entire process while invoking 'qsub'", function() it("should not block the entire process while invoking 'qsub'", function()
local copas = require "copas" local copas = require "copas"
local driver = module.new({ runtime_data_dir = tmpdir }, logger) local driver = module.new({ runtime_data_dir = utils.tmpdir }, logger)
local job = { local job = {
jid = 171, jid = 171,
...@@ -84,12 +43,25 @@ describe("SGA driver for PBS", function() ...@@ -84,12 +43,25 @@ describe("SGA driver for PBS", function()
data = {} data = {}
} }
local assertQsubWasCalled = expectCommand(0.1, "12345", "qsub", local assertQsubWasCalled = utils.expectCommand{
name = "qsub",
delay = 0.1,
stdout = "12345",
arguments = {
"-N", job.cmd_id, "-N", job.cmd_id,
"-V", "-V",
"-o", tmpdir.."/qsub_"..job.jid..".out", "-o", utils.tmpdir.."/qsub_"..job.jid..".out",
"-e", tmpdir.."/qsub_"..job.jid..".err", "-e", utils.tmpdir.."/qsub_"..job.jid..".err",
tmpdir.."/qsub_"..job.jid..".script") utils.tmpdir.."/qsub_"..job.jid..".script",
},
files = {
[utils.tmpdir.."/qsub_"..job.jid..".script"] = [[
#!/bin/sh
umask 002
my fake command
]]
}
}
local stage = 0 local stage = 0
......
local procdata = require "procdata" local procdata = require "procdata"
local module = require "sga.driver.posix" local module = require "sga.driver.posix"
local utils = require "test.driver.utils"
describe("SGA driver for POSIX", function() describe("SGA driver for POSIX", function()
local logger = { local logger = {
...@@ -16,6 +17,95 @@ describe("SGA driver for POSIX", function() ...@@ -16,6 +17,95 @@ describe("SGA driver for POSIX", function()
snapshot:revert() snapshot:revert()
end) end)
it("should report job with ended processes", function()
local driver = module.new({ runtime_data_dir = utils.tmpdir }, logger)
local job = {
jid = 171,
cmd_id = "User@AProj.CBOWZWVCYE",
sandboxes = {
utils.tmpdir.."/posixDriverSandbox",
},
parameters = {
csbase_command_path = ".",
csbase_command_output_path = utils.tmpdir,
csbase_command_root_path = utils.tmpdir,
},
data = {}
}
local cmdSpec = {
name = "myExecutedCommand",
childdelays = { 0.01, 0.05, 0.1 }, -- fast processes are not reported.
arguments = {
"one",
"other",
"another",
},
directories = job.sandboxes,
}
local function checkStatus(done)
local ok, result = module.actions.status(driver, job)
assert.is_true(ok)
assert.is_table(result)
local count = 0
local running = 0
local sgapid
local cmdprocids = {}
for i, procinfo in ipairs(result.processes) do
count = count+1
if procinfo.state == "RUNNING" then
running = running+1
else
assert.equal("FINISHED", procinfo.state)
end
assert.is_number(procinfo.pid)
assert.is_number(procinfo.ppid)
assert.equal("", procinfo.exec_host)
assert.is_string(procinfo.string)
assert.equal("", procinfo.processor_id)
assert.is_number(procinfo.memory_ram_size_mb)
assert.equal(0, procinfo.memory_swap_size_mb)
assert.equal(0, procinfo.cpu_perc)
assert.equal(0, procinfo.cpu_time_sec)
assert.is_number(procinfo.wall_time_sec)
assert.is_number(procinfo.system_time_sec)
assert.is_number(procinfo.user_time_sec)
assert.is_number(procinfo.virtual_memory_size_mb)
assert.equal(0, procinfo.bytes_in_kb)
assert.equal(0, procinfo.bytes_out_kb)
assert.equal(0, procinfo.disk_bytes_read_kb)
assert.equal(0, procinfo.disk_bytes_write_kb)
if i == 1 then
sgapid = procinfo.ppid
else
assert.truthy(cmdprocids[procinfo.ppid])
end
cmdprocids[procinfo.pid] = true
end
assert.truthy(count > 0)
assert.truthy(count <= 3+2*#cmdSpec.childdelays) -- fork+sh+cmd+n*(sh+sleep)
assert.truthy(running <= count)
if done then
assert.equal(0, running)
end
end
local cmdLine = cmdSpec.name.." "..table.concat(cmdSpec.arguments, " ")
local assertCmdWasCalled = utils.expectCommand(cmdSpec)
local ok = module.execute_command(driver, job, cmdLine)
assert.is_true(ok)
while not module.is_command_done(driver, job) do
checkStatus()
end
checkStatus("done")
assertCmdWasCalled()
end)
it("should list a single node", function() it("should list a single node", function()
local driver = module.new({ sga_name = "MySgaNameForTest" }, logger) local driver = module.new({ sga_name = "MySgaNameForTest" }, logger)
......
local lfs = require "lfs"
local assert = require "luassert"
local utils = { luabin = "" }
for i = 0, -math.huge, -1 do
if not arg[i] then
break
end
utils.luabin = arg[i]
end
utils.tmpdir = os.tmpname()
os.remove(utils.tmpdir)
lfs.mkdir(utils.tmpdir)
function utils.expectCommand(spec)
local resultPath = utils.tmpdir.."/"..spec.name..".out"
local cmdPath = "./"..spec.name
local file = assert(io.open(cmdPath, "w"))
file:write([[
#!]]..utils.luabin..[[
package.path = "]]..package.path..[["
package.cpath = "]]..package.cpath..[["
local lfs = require "lfs"
local socket = require "socket.core"
local cmd = "]]..spec.name..[["
io.output("]]..resultPath..[[")
local function fail(message, ...)
io.write(string.format(message, ...))
os.exit(127)
end
local function expectArg(index, expected)
local actual = arg[index]
if actual ~= expected then
fail("%q argument #%d expected to be %q, but was %q",
cmd, index, expected, tostring(actual))
end
end
local function expectDir(path)
if lfs.attributes(path, "mode") ~= "directory" then
fail("%q expected directory %q to be available", cmd, path)
end
end
local function expectFile(path, expected)
if lfs.attributes(path, "mode") ~= "file" then
fail("%q expected file %q to exist", cmd, path)
elseif expected then
local file = assert(io.open(path))
local actual = file:read("*a")
if actual ~= expected then
fail("%q expected file %q to have different contents", cmd, path)
end
end
end
]])
for i, value in ipairs(spec.arguments or {}) do
assert(type(value) == "string")
file:write(string.format('expectArg(%d, %q)\n', i, value))
end
for i, value in ipairs(spec.directories or {}) do
assert(type(value) == "string")
file:write(string.format('expectDir(%q)\n', value))
end
for path, contents in pairs(spec.files or {}) do
if type(contents) == "string" then
file:write(string.format('expectFile(%q, %q)\n', path, contents))
else
file:write(string.format('expectFile(%q)\n', path))
end
end
if spec.code then
file:write(spec.code)
else
if spec.delay then
file:write(string.format('socket.sleep(%g)\n', spec.delay))
end
if spec.stdout then
file:write(string.format('io.stdout:write(%q)\n', spec.stdout))
end
if spec.stderr then
file:write(string.format('io.stderr:write(%q)\n', spec.stderr))
end
file:write('local pipes = {}\n')
for i, delay in ipairs(spec.childdelays or {}) do
file:write(string.format('table.insert(pipes, assert(io.popen("sleep %g")))\n', delay))
end
file:write('for _, pipe in ipairs(pipes) do\n',
' pipe:close()\n',
'end\n')
end
file:write('io.write(table.concat(arg, " "))\n')
file:close()
os.execute("chmod 700 "..cmdPath)
local expected = string.format(table.concat(spec.arguments, " "))
return function ()
local file = assert(io.open(resultPath))
local args = file:read("*a")
file:close()
os.remove(resultPath)
os.remove(cmdPath)
assert.equal(expected, args)
end
end
return utils
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment