Skip to content

Commit 250038c

Browse files
committed
tests: synchronizes the test with luakit’s internal idle queue.
- Introducing wait_for_idle() to synchronize with the internal idle queue. This ensures, that all code scheduled by luakit.idle_add() are run. For example signal connections by modules like undoclose. - It does oes not wait for a page or tab to load like wait_for_view(..). Tests are run faster than luakit can load (require) files. This makes tests unreliable. It's not an issue for luakit itself, because a user can't interract with it before the UI is loaded.
1 parent 2e8b149 commit 250038c

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

tests/async/test_completion.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ local T = {}
66
local assert = require("luassert")
77

88
uris = {"about:blank"}
9+
10+
local test = require("tests.lib")
911
require "config.rc"
1012

1113
local window = require "window"
1214
local w = assert(select(2, next(window.bywidget)))
1315

1416
T.test_leaving_completion_restores_correct_input_text = function ()
17+
test.wait_for_idle()
1518
local input = w.ibar.input
1619

1720
w:enter_cmd(":tab")

tests/async/test_memory_leaks.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
-- @copyright 2017 Aidan Holm <aidanholm@gmail.com>
44

55
uris = {"about:blank"}
6+
7+
local test = require("tests.lib")
68
require "config.rc"
79

810
local window = require "window"
@@ -11,6 +13,7 @@ local w = assert(select(2, next(window.bywidget)))
1113
local T = {}
1214

1315
T.test_webview_from_closed_tab_is_released = function ()
16+
test.wait_for_idle()
1417
local refs = setmetatable({}, { __mode = "k" })
1518
refs[w.view] = true
1619
w:close_tab()

tests/async/test_scroll.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local window = require "window"
1313
local w = assert(select(2, next(window.bywidget)))
1414

1515
T.test_scrolling_works = function ()
16+
test.wait_for_idle()
1617
test.wait_for_view(w.view)
1718

1819
-- Fetch height of document body

tests/async/test_undoclose.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local window = require "window"
1515
local w = assert(select(2, next(window.bywidget)))
1616

1717
T.test_undo_close_restores_tab_history = function ()
18+
test.wait_for_idle()
1819
-- Load page in new tab
1920
local uri = test.http_server() .. "undoclose_page.html"
2021
w:new_tab(uri)

tests/lib.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ function _M.init(arg)
1616
shared_lib = arg
1717
end
1818

19+
--- Pause test execution until the next idle event in the main event loop.
20+
--
21+
-- Schedules a one-shot resume callback using `luakit.idle_add()` and
22+
-- suspends the test coroutine until the event loop is next idle.
23+
-- This ensures all pending `idle_add` hooks ("post-require" module
24+
-- initializations) are executed before subsequent test code runs.
25+
--
26+
-- Does nothing if called outside of the test context.
27+
function _M.wait_for_idle()
28+
local luakit = require "luakit"
29+
luakit.idle_add(_M.continue)
30+
_M.wait()
31+
end
32+
1933
--- Pause test execution until a webview widget finishes loading.
2034
--
2135
-- @tparam widget view The webview widget to wait on.

0 commit comments

Comments
 (0)