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

gateway: Test concurrent rinfo for main_thread_only #274

Closed

Conversation

zmedico
Copy link
Contributor

@zmedico zmedico commented Apr 19, 2024

Add test coverage for a bug triggered by pytest-cov when it tried to call _rinfo after the gateway was already busy with a remote_exec call:

pytest-dev/pytest-xdist#1071

@webknjaz
Copy link
Member

Looks like something that would benefit from having an intentional test? And maybe some smoke tests with pytest-cov and pytest-xdist in the same env?

@zmedico zmedico force-pushed the main_thread_only-cache-gateway-rinfo branch 2 times, most recently from 513cf7b to 2814ae9 Compare April 19, 2024 23:41
@zmedico zmedico marked this pull request as draft April 20, 2024 00:02
testing/test_gateway.py Outdated Show resolved Hide resolved
@zmedico zmedico force-pushed the main_thread_only-cache-gateway-rinfo branch from 2814ae9 to 95a25c3 Compare April 21, 2024 07:39
@zmedico zmedico marked this pull request as ready for review April 21, 2024 07:39
@webknjaz
Copy link
Member

@bluetech @RonnyPfannschmidt @nicoddemus I can't request reviews in this repo so tagging you instead.

This PR looks ready to be checked/merged.

@bluetech
Copy link
Member

@zmedico Thanks for following up!

It seems to me better to merge pytest-dev/pytest-xdist#1072 and not this. It seems intentional that execnet doesn't request rinfo always, allowing the user to choose whether to grab the info from the remote. But this change will "force" it.

The issue seems to me to be specific to xdist and pytest plugin architecture, where xdist can't control what another plugin does, otherwise it would simply avoid the issue.

WDYT?

@zmedico
Copy link
Contributor Author

zmedico commented Apr 27, 2024

@zmedico Thanks for following up!

It seems to me better to merge pytest-dev/pytest-xdist#1072 and not this. It seems intentional that execnet doesn't request rinfo always, allowing the user to choose whether to grab the info from the remote. But this change will "force" it.

The issue seems to me to be specific to xdist and pytest plugin architecture, where xdist can't control what another plugin does, otherwise it would simply avoid the issue.

WDYT?

Yes, I agree that is nicer to allow a choice here. I suppose pytest-cov is not in a position to cache the rinfo, so it makes sense for pytest-xdist to handle it for backward compatibility.

I've adjusted this PR to just add test_concurrent_rinfo, and perform the rinfo caching for main_thread_only right inside the test,

Noted the change here: pytest-dev/pytest-xdist#1071 (comment)

zmedico added a commit to zmedico/pytest-xdist that referenced this pull request Apr 27, 2024
Cache execnet gateway info during WorkerController setup for backward
compatibility, in order to avoid a later main_thread_only deadlock
error triggered when pytest-cov calls rinfo after the main thread is
already busy. See pytest-dev/execnet#274 for corresponding test case.

Fixes: 20e3ac7 ("Use execnet main_thread_only execmodel (pytest-dev#1027)")
Add test coverage for a bug triggered by pytest-cov when it
tried to call _rinfo after the gateway was already busy with
a remote_exec call:

pytest-dev/pytest-xdist#1071
@zmedico zmedico force-pushed the main_thread_only-cache-gateway-rinfo branch from 38c698c to af78844 Compare April 27, 2024 18:33
@zmedico zmedico changed the title gateway: Cache rinfo for main_thread_only gateway: Test concurrent rinfo for main_thread_only Apr 27, 2024
@bluetech
Copy link
Member

@zmedico I admit I'm a bit confused what the test is testing. What is the failure it is testing against?

# rinfo while the main thread is busy with the pytest-xdist
# WorkerController's remote_exec call.
gw._rinfo()
assert hasattr(gw, "_cache_rinfo")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zmedico I admit I'm a bit confused what the test is testing. What is the failure it is testing against?

If we omit the above gw._rinfo() call then this test case reproduces the underlying issue from pytest-dev/pytest-xdist#1071:

  File "execnet/testing/test_gateway.py", line 682, in test_concurrent_rinfo
    rinfo = gw._rinfo()
            ^^^^^^^^^^^
  File "execnet/src/execnet/gateway.py", line 87, in _rinfo
    self._cache_rinfo = RInfo(ch.receive())
                              ^^^^^^^^^^^^
  File "execnet/src/execnet/gateway_base.py", line 934, in receive
    raise self._getremoteerror() or EOFError()
execnet.gateway_base.RemoteError: concurrent remote_exec would cause deadlock for main_thread_only execmodel

Copy link
Member

Choose a reason for hiding this comment

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

Right but that failure is expected right? And we're testing that adding the extra _rinfo call prevents it from happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to provide some test coverage for the scenario that led to pytest-dev/pytest-xdist#1071, since this sort of coverage could have prevented a broken release of pytest-xdist.

bluetech pushed a commit to zmedico/pytest-xdist that referenced this pull request Apr 28, 2024
Cache execnet gateway info during WorkerController setup for backward
compatibility, in order to avoid a later main_thread_only deadlock
error triggered when pytest-cov calls rinfo after the main thread is
already busy. See pytest-dev/execnet#274 for corresponding test case.

Fixes: 20e3ac7 ("Use execnet main_thread_only execmodel (pytest-dev#1027)")
@zmedico
Copy link
Contributor Author

zmedico commented Jun 10, 2024

Closed in favor of pytest-dev/pytest-xdist#1072.

@zmedico zmedico closed this Jun 10, 2024
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.

4 participants