From a08191913e21727f97be92817fb64da8aa37e6b5 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 28 Oct 2021 21:12:07 -0700 Subject: [PATCH] tests: Blind attempt at making a flacky test under luajit stable. I could not reproduce the issue locally. --- tests/_client.lua | 35 +++++++++++++++++++++++++++++++---- tests/test-input-binding.lua | 18 ++++++++++++++++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/tests/_client.lua b/tests/_client.lua index 5b58f7923..ac3f1b6c5 100644 --- a/tests/_client.lua +++ b/tests/_client.lua @@ -1,4 +1,5 @@ local spawn = require("awful.spawn") +local gtimer = require("gears.timer") local lua_executable = os.getenv("LUA") if lua_executable == nil or lua_executable == "" then @@ -118,13 +119,15 @@ local lgi = require("lgi") local Gio = lgi.require("Gio") local initialized = false -local pipe +local pipe, pid + local function init() if initialized then return end initialized = true local cmd = { lua_executable, "-e", test_client_source } - local _, _, stdin, stdout, stderr = awesome.spawn(cmd, false, true, true, true) - pipe = Gio.UnixOutputStream.new(stdin, true) + local _pid, _, stdin, stdout, stderr = awesome.spawn(cmd, false, true, true, true) + pipe = Gio.UnixOutputStream.new(stdin, true) + pid = _pid stdout = Gio.UnixInputStream.new(stdout, true) stderr = Gio.UnixInputStream.new(stderr, true) spawn.read_lines(stdout, function(...) print("_client", ...) end) @@ -139,7 +142,29 @@ local function get_snid(sn_rules, callback) return snid end -return function(class, title, sn_rules, callback, resize_increment, args) +local module = {} + +function module.terminate() + if not initialized then return end + + for _, c in ipairs(client.get()) do + c:kill() + end + + pipe:close() + initialized, pipe = false, nil + + -- Make a copy to avoid the re-initialized race condition. + local original_pid = pid + + gtimer.delayed_call(function() + awesome.kill(original_pid, 9) + end) + + return true +end + +local function new(_, class, title, sn_rules, callback, resize_increment, args) args = args or {} class = class or "test_app" title = title or "Awesome test client" @@ -200,4 +225,6 @@ return function(class, title, sn_rules, callback, resize_increment, args) return snid end +return setmetatable(module, {__call = new }) + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-input-binding.lua b/tests/test-input-binding.lua index 99fdce49c..a52a19da8 100644 --- a/tests/test-input-binding.lua +++ b/tests/test-input-binding.lua @@ -243,8 +243,20 @@ for _, type_name in ipairs { "key", "button" } do end) -- Cleanup (otherwise there is a race with the root.buttons tests) - table.insert(steps, function() - if #mouse.screen.clients ~= 0 then return end + table.insert(steps, function(count) + if #mouse.screen.clients ~= 0 then + if count > 5 then + -- It's stuck, kill it. + test_client.terminate() + else + for _, c in pairs(client.get()) do + c:kill() + end + end + + + return + end return true end) @@ -372,6 +384,8 @@ table.insert(steps, function() return true end) +table.insert(steps, test_client.terminate) + runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80