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

Terminate the test loop if shouldfail or shouldstop is set #1026

Merged
merged 11 commits into from
Apr 1, 2024
Merged

Terminate the test loop if shouldfail or shouldstop is set #1026

merged 11 commits into from
Apr 1, 2024

Conversation

bbrown1867
Copy link
Contributor

@bbrown1867 bbrown1867 commented Feb 23, 2024

Terminate the test loop if shouldfail or shouldstop is set in a worker's pytest session

Closes #1024.

@bbrown1867 bbrown1867 marked this pull request as ready for review February 23, 2024 22:31
@bbrown1867 bbrown1867 changed the title Terminate the test loop on a worker if shouldfail or shouldstop is set Terminate the test loop if shouldfail or shouldstop is set Feb 23, 2024
src/xdist/remote.py Show resolved Hide resolved
src/xdist/dsession.py Outdated Show resolved Hide resolved
testing/acceptance_test.py Show resolved Hide resolved
testing/acceptance_test.py Outdated Show resolved Hide resolved
src/xdist/dsession.py Outdated Show resolved Hide resolved
@bbrown1867
Copy link
Contributor Author

@bluetech are we good to merge?

@bbrown1867
Copy link
Contributor Author

@bluetech I found a new solution that does the same thing (stopping the worker when the global max is reached) without needing any changes to dsession.py. Let me know what you think!

@bluetech
Copy link
Member

If I understand the new solution, when reaching shouldstop it "drains" the remaining items from the worker by fake-executing them and reporting them to the DSession. I have a feeling that this faking is going to cause some issues since we're basically skipping over the entire interior of the runtest protocol. Perhaps the assumption is that by this point, the DSession has already processed its own shouldstop and is preparing to shutdown, but this is the sort of race we want to avoid.

Reading the code, I'm thinking perhaps we go back to something like the previous solution, but make it safe.
Previously the worker would just stop, and the dsession would interpret it as a crash, which it might as well have been, no way to know.
I think instead we can add the worker's shouldstop to the worker_workerfinished message. If the dsession sees it, it knows it's not a crash and it can set its own shouldstop (if not already set) and shutdown.

I'm not sure it would work out, but if does I think it will fix the issue cleanly. WDYT?

@bbrown1867
Copy link
Contributor Author

I'm not sure it would work out, but if does I think it will fix the issue cleanly. WDYT?

Yeah I agree that is a cleaner solution and I like that it propagates the worker session shouldstop/shouldfail status to the DSession. I took a stab at this in c927b1a and it seems to work on the example from #1024.

(.venv) % pytest test_parallel.py  -n 2  -s --maxfail=1
======================================================================== test session starts =========================================================================
platform darwin -- Python 3.8.13, pytest-8.0.0, pluggy-1.4.0
configfile: tox.ini
plugins: xdist-0.1.dev1152+ge11ad4d
2 workers [4 items]
### executing fixture! ###
### executing fixture! ###
F..
============================================================================== FAILURES ==============================================================================
_______________________________________________________________________________ test_1 _______________________________________________________________________________
[gw0] darwin -- Python 3.8.13 /Users/bbrown/Development/fun/pytest-xdist/.venv/bin/python

    def test_1():
>       assert False
E       assert False

test_parallel.py:16: AssertionError
====================================================================== short test summary info =======================================================================
FAILED test_parallel.py::test_1 - assert False
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xdist.dsession.Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==================================================================== 1 failed, 2 passed in 2.49s =====================================================================

The failure occurs on gw0 and it exits. gw1 runs both tests successfully, finishing before the failure propagates from gw0 to DSession.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, I think the approach is good now. I left a couple of comments on the code.

src/xdist/dsession.py Outdated Show resolved Hide resolved
src/xdist/dsession.py Outdated Show resolved Hide resolved
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will merge in a few days, maybe @RonnyPfannschmidt or @nicoddemus want to take a look as well.

@bluetech
Copy link
Member

@bbrown1867 Can you add a changelog/1024.bugfix changelog entry? Would do it myself but no permission to push to your fork. I wrote this entry if you want to use it:

Added proper handling of ``shouldstop`` (such as set by ``--max-fail``) and ``shouldfail`` conditions in workers.
Previously, a worker might have continued executing further tests before the controller could terminate the session.

@bbrown1867
Copy link
Contributor Author

@bbrown1867 Can you add a changelog/1024.bugfix changelog entry? Would do it myself but no permission to push to your fork. I wrote this entry if you want to use it:

Done! Thanks for drafting that

@bluetech bluetech merged commit 84df445 into pytest-dev:master Apr 1, 2024
21 checks passed
@bbrown1867 bbrown1867 deleted the bbrown1867/1024/exit-faster-when-xfailed branch April 2, 2024 14:34
bluetech pushed a commit to pytest-dev/pytest that referenced this pull request May 2, 2024
…2279)

Closes #11706.

Originally fixed in #11721, but then reverted in #12022 due to a regression in pytest-xdist.

The regression was fixed on the pytest-xdist side in pytest-dev/pytest-xdist#1026.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session-scoped fixture executed too many times with -x / --maxfails
3 participants