Skip to content

Commit

Permalink
broken in unit tests; adding more exhaustive tests, failing at the pa…
Browse files Browse the repository at this point in the history
…rt where we try to change a check's params.
  • Loading branch information
Ken Wronkiewicz committed Apr 25, 2012
1 parent 49d11da commit bddb841
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion agents/monitoring/lua/lib/schedule/scheduler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ function Scheduler:start()
self._scanner:scanStates()
end

-- Scheduler is in charge of determining if a check should be run and then maintaining the state of the checks.
function Scheduler:numChecks()
return #self._checks
end

-- We can rebuid it. We have the technology. Better.. faster.. stronger..
-- checks: a table of BaseChecks
-- callback: function called after the state file is written
function Scheduler:rebuild(checks, callback)
Expand Down
35 changes: 33 additions & 2 deletions agents/monitoring/tests/schedule/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ local checks3 = {
}
local checks4 = {
BaseCheck:new({id='ch0002', state='OK', period=1, path=path.join(tmp, '0002.chk')}),
}
local checks5 = {
BaseCheck:new({id='ch0002', state='OK', period=1, path=path.join(tmp, '0002.chk')}),
}
local checks6 = {
BaseCheck:new({id='ch0001', state='OK', period=1, path=path.join(tmp, '0001.chk')}),
}
local checks7 = {
BaseCheck:new({id='ch0001', state='OK', period=2, path=path.join(tmp, '0001.chk')}),
}
async.waterfall({
function(callback)
Expand All @@ -121,18 +130,40 @@ local checks4 = {
local timeout = timer.setTimeout(5000, function()
-- they all should have run.
asserts.equals(scheduler._runCount, 10)
asserts.equals(scheduler:numChecks(), 2)
scheduler:rebuild(checks4, callback);
end)
end,
function(callback)
scheduler:start()
local timeout = timer.setTimeout(5000, function()
asserts.equals(scheduler:numChecks(), 1)
-- tests are a bit dicey at this point depending on exactly where in the clock we are..
asserts.ok(scheduler._runCount >= 15)
asserts.ok(scheduler._runCount <= 18)
callback()
end)
end
end,
function(callback)
scheduler:rebuild(checks5, callback)
end,
function(callback)
asserts.equals(scheduler:numChecks(), 1)
scheduler:rebuild(checks6, callback)
end,
function(callback)
asserts.equals(scheduler:numChecks(), 1)
scheduler:rebuild(checks7, callback)
end,
function(callback)
asserts.equals(scheduler:numChecks(), 1)
local timeout = timer.setTimeout(3000, function()
asserts.equals(scheduler:numChecks(), 1)
-- tests are a bit dicey at this point depending on exactly where in the clock we are..
asserts.ok(scheduler._runCount >= 15)
asserts.ok(scheduler._runCount <= 18)
callback()
end)
end,
}, function(err)
asserts.ok(err == nil)
test.done()
Expand Down

0 comments on commit bddb841

Please sign in to comment.