mirror of
https://github.com/koreader/koreader
synced 2024-11-11 19:11:14 +00:00
e257c4e45e
The methods used here will likely work on most embedded devices, which is why I put them in their own WakeupMgr interface/scheduler module, separate from Kobo. See https://www.mobileread.com/forums/showthread.php?p=3886403#post3886403 for more context. Fixes #3806.
56 lines
2.1 KiB
Lua
56 lines
2.1 KiB
Lua
describe("WakeupMgr", function()
|
|
local RTC
|
|
local WakeupMgr
|
|
local epoch1, epoch2, epoch3
|
|
|
|
setup(function()
|
|
require("commonrequire")
|
|
package.unloadAll()
|
|
RTC = require("ffi/rtc")
|
|
WakeupMgr = require("device/wakeupmgr")
|
|
-- We could theoretically test this by running the tests as root locally.
|
|
stub(WakeupMgr, "setWakeupAlarm")
|
|
WakeupMgr.validateWakeupAlarmByProximity = spy.new(function() return true end)
|
|
|
|
epoch1 = RTC:secondsFromNowToEpoch(1234)
|
|
epoch2 = RTC:secondsFromNowToEpoch(123)
|
|
epoch3 = RTC:secondsFromNowToEpoch(9999)
|
|
end)
|
|
|
|
it("should add a task", function()
|
|
WakeupMgr:addTask(1234, function() end)
|
|
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
|
|
assert.stub(WakeupMgr.setWakeupAlarm).was.called(1)
|
|
end)
|
|
it("should add a task in order", function()
|
|
WakeupMgr:addTask(9999, function() end)
|
|
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
|
|
assert.stub(WakeupMgr.setWakeupAlarm).was.called(1)
|
|
|
|
WakeupMgr:addTask(123, function() end)
|
|
assert.is_equal(epoch2, WakeupMgr._task_queue[1].epoch)
|
|
assert.stub(WakeupMgr.setWakeupAlarm).was.called(2)
|
|
end)
|
|
it("should execute top task", function()
|
|
assert.is_true(WakeupMgr:wakeupAction())
|
|
end)
|
|
it("should have removed executed task from stack", function()
|
|
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
|
|
assert.is_equal(epoch3, WakeupMgr._task_queue[2].epoch)
|
|
end)
|
|
it("should have scheduled next task after execution", function()
|
|
assert.stub(WakeupMgr.setWakeupAlarm).was.called(3)
|
|
end)
|
|
it("should remove arbitrary task from stack", function()
|
|
WakeupMgr:removeTask(2)
|
|
assert.is_equal(epoch1, WakeupMgr._task_queue[1].epoch)
|
|
assert.is_equal(nil, WakeupMgr._task_queue[2])
|
|
end)
|
|
it("should execute last task", function()
|
|
assert.is_true(WakeupMgr:wakeupAction())
|
|
end)
|
|
it("should not have scheduled a wakeup without a task", function()
|
|
assert.stub(WakeupMgr.setWakeupAlarm).was.called(3)
|
|
end)
|
|
end)
|