fix(github_actions): Fix clients lingering into subsequent tests

On GitHub Actions, clients created in some tests take too long to close
and still exist when the next test has started. This can affect certain
tests that rely on a specific client count or simply produce a race
condition within `scan` in `awesome.c`.

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
Lucas Schwiderski 2021-03-15 18:55:00 +01:00
parent 8f39fb61bd
commit 5c3b739c25
No known key found for this signature in database
GPG Key ID: AA12679AAA6DF4D8
2 changed files with 29 additions and 2 deletions

View File

@ -185,6 +185,20 @@ fi
start_awesome() {
cd "$build_dir"
# On some systems clients from a test may still linger for a while until they
# are fully killed. Since this can affect susequent tests, we wait until all
# of them are gone.
# The check command needs to call `xlsclients` twice:
# 1. Test the stdout of `xlsclients` and make sure there are no clients left.
# 2. Check and fail if `xlsclients` itself fails. Print its stderr, if any.
# This is due to the fact that, if `xlsclient` return non-0, the `wc` would
# still report `0`. The order of commands makes sure that `xlsclient` is only
# called twice when needed. If there are still clients left, the `[` will
# shotcurcuit.
wait_until_success \
'wait for X clients from previous test to close' \
"[ \$(DISPLAY="$D" xlsclients | wc -l) -eq 0 ] && DISPLAY="$D" xlsclients > /dev/null"
# Kill awesome after $TEST_TIMEOUT seconds (e.g. for errors during test setup).
# SOURCE_DIRECTORY is used by .luacov.
DISPLAY="$D" SOURCE_DIRECTORY="$source_dir" \

View File

@ -85,12 +85,25 @@ local steps = {
-- Test that we have a client and that it's invalid (tostring()
-- causes an "invalid object" error)
local success, msg = pcall(function() tostring(objs[1]) end)
assert(not success)
assert(not success, msg)
assert(msg:find("invalid object"), msg)
-- Check that it is garbage-collectable
collectgarbage("collect")
assert(#objs == 0)
-- On GitHub Actions, it can take a while for clients to be killed
-- properly.
local tries = 0
while (#objs > 0 and tries < 60) do
os.execute("sleep 1")
tries = tries + 1
end
if tries > 0 then
print("Took approx. " .. tries .. " seconds to clean leaked client")
end
assert(#objs == 0, "still clients left after garbage collect")
return true
end
end,