Permalink
Browse files

broken in unit tests; adding more exhaustive tests, failing at the pa…

…rt where we try to change a check's params.
  • Loading branch information...
1 parent 49d11da commit bddb841f203e245d5f3db34e8482a4ea988e2399 Ken Wronkiewicz committed Apr 25, 2012
Showing with 38 additions and 3 deletions.
  1. +5 −1 agents/monitoring/lua/lib/schedule/scheduler.lua
  2. +33 −2 agents/monitoring/tests/schedule/init.lua
@@ -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)
@@ -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)
@@ -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()

0 comments on commit bddb841

Please sign in to comment.