Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mtest: improve interrupting tests on Win32 #14311

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pks-t
Copy link
Contributor

@pks-t pks-t commented Feb 28, 2025

Interrupting tests on Windows is a bit of a mess right now: instead of
cleanly shutting down, Meson tends to send you heaps of exceptions of
various kinds. This seems to stem from the fact that on Windows, asyncio
does not properly support handling of signals, and thus we don't install
any signal handlers at all that would allow us to shut down the test
processes.

Work around the issue by using the low-level run_until_complete()
function instead of asyncio.run(). This low-level function does not
perform the same level of careful teardown, but due to that it also
causes us to not spew out heaps of errors.

We should likely roll back these changes if asyncio ever was to gain
support for proper signal handling, or if we were able to ever address
all of the exceptions. But until then, allowing for a clean shutdown
that doesn't overwhelm the user with errors feels preferable.


I'm not hugely familiar with asyncio, so I would very much ask you to be extra critical of the approach chosen in this PR. It works for me on Windows and I do see clean shutdown. One omission is that tests that have been cancelled do not get marked accordingly anymore, but first I'd like to get some feedback on the current approach before trying to fix that.

In the subsequent commit we're about to adapt how the event loop on
Windows is terminated such that we can handle keyboard interrupts
better on that platform. With this change, it can happen that we're
trying to await the progress task of the `ConsoleLogger` class, but at
that time the loop would've already been in cancelled state and thus
awaiting the task fails. The end result is that we never print the
summary at all in such cases.

Prepare for this change by splitting up the logic to stop loggers in the
event loop and printing the summary. Like this, we can call `finish()`
on the logger outside of the event loop regardless of whether or not we
have awaited whatever internal state the logger has.

Signed-off-by: Patrick Steinhardt <[email protected]>
Interrupting tests on Windows is a bit of a mess right now: instead of
cleanly shutting down, Meson tends to send you heaps of exceptions of
various kinds. This seems to stem from the fact that on Windows, asyncio
does not properly support handling of signals, and thus we don't install
any signal handlers at all that would allow us to shut down the test
processes.

Work around the issue by using the low-level `run_until_complete()`
function instead of `asyncio.run()`. This low-level function does not
perform the same level of careful teardown, but due to that it also
causes us to not spew out heaps of errors.

We should likely roll back these changes if asyncio ever was to gain
support for proper signal handling, or if we were able to ever address
all of the exceptions. But until then, allowing for a clean shutdown
that doesn't overwhelm the user with errors feels preferable.

Signed-off-by: Patrick Steinhardt <[email protected]>
@bonzini bonzini added test targets OS:windows Winodows OS specific issues labels Feb 28, 2025
@jpakkane
Copy link
Member

jpakkane commented Mar 1, 2025

I don't understand asyncio that deeply myself but LGTM.

@bonzini
Copy link
Collaborator

bonzini commented Mar 1, 2025

I will check a bit against the python sources, thanks for proposing a solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS:windows Winodows OS specific issues test targets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants