pbs.lua 1.81 KB
Newer Older
1
2
local copas = require "copas"
local module = require "sga.driver.pbs"
3
local utils = require "test.driver.utils"
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

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"

36
    local driver = module.new({ runtime_data_dir = utils.tmpdir }, logger)
37
38
39
40
41
42
43
44
45

    local job = {
      jid = 171,
      cmd_id = "User@AProj.CBOWZWVCYE",
      sandboxes = {},
      parameters = {},
      data = {}
    }

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    local assertQsubWasCalled = utils.expectCommand{
      name = "qsub",
      delay = 0.1,
      stdout = "12345",
      arguments = {
        "-N", job.cmd_id,
        "-V",
        "-o", utils.tmpdir.."/qsub_"..job.jid..".out",
        "-e", utils.tmpdir.."/qsub_"..job.jid..".err",
        utils.tmpdir.."/qsub_"..job.jid..".script",
      },
      files = {
        [utils.tmpdir.."/qsub_"..job.jid..".script"] = [[
#!/bin/sh
umask 002
my fake command
]]
      }
    }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

    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)