Commit 3dfed78e authored by Renato Figueiro Maia's avatar Renato Figueiro Maia
Browse files

Teste da correção de chamada assíncrona aos comandos do PBS.

[SOMA-6606][SOMA-6593]
parent 569a141f
......@@ -96,6 +96,7 @@ test:
- test/lua_runtime/bin/luarocks install --server=https://luarocks.org busted
- export PATH=".:${PATH}" # to use mockup commands like 'qsub' from PBS
- test/lua_runtime/bin/busted test/driver/posix.lua
- test/lua_runtime/bin/busted test/driver/pbs.lua
#-------------------------
# Docker Jobs
......
......@@ -46,7 +46,7 @@ function pbs.execute_command(self, job, cmd_string, user_token)
self.exec:chmod(sandbox_path, "rwxrwxrwx")
end
local token_env
local token_env = ""
if user_token then
token_env = "CSBASE_USER_TOKEN=" .. user_token .. " "
end
......
local copas = require "copas"
local module = require "sga.driver.pbs"
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 function errorHandler(...)
local tracemsg = debug.traceback(...)
print(tracemsg)
table.insert(threadErrors, tracemsg)
end
local function newThread(f, ...)
copas.addthread(xpcall, f, errorHandler, ...)
end
describe("SGA driver for PBS", function()
local logger = {
error = function () end,
debug = function () end,
}
before_each(function()
snapshot = assert:snapshot()
mock(logger)
end)
after_each(function()
snapshot:revert()
end)
it("should not block the entire process while invoking 'qsub'", function()
local copas = require "copas"
local driver = module.new({ runtime_data_dir = tmpdir }, logger)
local job = {
jid = 171,
cmd_id = "User@AProj.CBOWZWVCYE",
sandboxes = {},
parameters = {},
data = {}
}
local assertQsubWasCalled = expectCommand(0.1, "12345", "qsub",
"-N", job.cmd_id,
"-V",
"-o", tmpdir.."/qsub_"..job.jid..".out",
"-e", tmpdir.."/qsub_"..job.jid..".err",
tmpdir.."/qsub_"..job.jid..".script")
local stage = 0
newThread(function ()
copas.sleep(0) -- yield
assert.equal(0, stage)
stage = 1
end)
newThread(function ()
local ok = module.execute_command(driver, job, "my fake command")
assertQsubWasCalled()
assert.is_true(ok)
assert.equal(1, stage)
stage = 2
end)
copas.loop()
assert.equal(2, stage)
assert.same({}, threadErrors)
end)
end)
Markdown is supported
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