diff --git a/tests/run.sh b/tests/run.sh index 592b7646..f2902f8f 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -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" \ diff --git a/tests/test-leak-client.lua b/tests/test-leak-client.lua index 12b520e4..9f326750 100644 --- a/tests/test-leak-client.lua +++ b/tests/test-leak-client.lua @@ -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,