From e52c74afcc1c11685a1afdf56ea0765f3de11663 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 7 Mar 2016 22:52:52 -0800 Subject: [PATCH] test: more uimanager scheduler test --- frontend/dump.lua | 4 ++-- frontend/ui/uimanager.lua | 4 +--- kodev | 4 +++- spec/unit/uimanager_spec.lua | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/frontend/dump.lua b/frontend/dump.lua index 242ca1e08..91eff5ebb 100644 --- a/frontend/dump.lua +++ b/frontend/dump.lua @@ -49,7 +49,7 @@ local function _serialize(what, outt, indent, max_lv, history) elseif type(what) == "number" then if isUbuntuTouch then -- FIXME: the `SDL_CreateRenderer` function in Ubuntu touch somehow - -- use a strange locale that formats number like this: 1.10000000000000g+02 + -- use a strange locale that formats number like this: 1.10000000000000g+02 -- which cannot be recognized by loadfile after the number is dumped. -- Here the workaround is to preserve enough precision in "%.13e" format. insert(outt, string.format("%.13e", what)) @@ -59,7 +59,7 @@ local function _serialize(what, outt, indent, max_lv, history) elseif type(what) == "boolean" then insert(outt, tostring(what)) elseif type(what) == "function" then - insert(outt, "nil --[[ FUNCTION ]]") + insert(outt, tostring(what)) elseif type(what) == "nil" then insert(outt, "nil") end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 1e145ddd6..f50bbca89 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -227,9 +227,7 @@ end -- UIManager:unschedule(self.anonymousFunction) function UIManager:unschedule(action) for i = #self._task_queue, 1, -1 do - local task = self._task_queue[i] - if task.action == action then - -- remove from table + if self._task_queue[i].action == action then table.remove(self._task_queue, i) end end diff --git a/kodev b/kodev index cbdc21a35..d300d6a37 100755 --- a/kodev +++ b/kodev @@ -309,7 +309,9 @@ OPTIONS: if [ ! -z $2 ]; then test_path="${test_path}/$2" fi - busted --lua=./luajit ${opts} -o ./spec/$1/unit/verbose_print --exclude-tags=notest ${test_path} + busted --lua=./luajit ${opts} \ + -o ./spec/$1/unit/verbose_print \ + --exclude-tags=notest ${test_path} popd } diff --git a/spec/unit/uimanager_spec.lua b/spec/unit/uimanager_spec.lua index b7b170bcc..ac2676963 100644 --- a/spec/unit/uimanager_spec.lua +++ b/spec/unit/uimanager_spec.lua @@ -113,6 +113,25 @@ describe("UIManager spec", function() assert.are.same('quux', UIManager._task_queue[5].action) end) + it("should unschedule all the tasks with the same action", function() + local now = { util.gettime() } + local noop1 = function() end + UIManager:quit() + UIManager._task_queue = { + { time = {now[1] - 15, now[2] }, action = '3' }, + { time = {now[1] - 10, now[2] }, action = '1' }, + { time = {now[1], now[2] - 6 }, action = '3' }, + { time = {now[1], now[2] - 5 }, action = '2' }, + { time = now, action = '3' }, + } + -- insert into the tail slot + UIManager:unschedule('3') + assert.are.same({ + { time = {now[1] - 10, now[2] }, action = '1' }, + { time = {now[1], now[2] - 5 }, action = '2' }, + }, UIManager._task_queue) + end) + it("should not have race between unschedule and _checkTasks", function() local now = { util.gettime() } local run_count = 0