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

gh-93357: Lay the foundation for further work in asyncio.test_streams: port server cases to IsolatedAsyncioTestCase #93369

Merged
merged 11 commits into from
Oct 4, 2022

Conversation

arhadthedev
Copy link
Member

@arhadthedev arhadthedev commented May 31, 2022

This PR removes ad-hoc implementation of async tests by using all relatively new features of standard IsolatedAsyncIoTestCase.

Edit: this PR also removes messages variable used to pass exceptions between a main and a server threads. That's because the server is now async, lives in a main thread, and needs no intermediary to pass exceptions into a test harness.

To make changes possible to review, this PR changes a limited set of tests only. Further commits will expand the change further up and down.

For this, a single test class is temporarily split into three parts; two of them (StreamTests and StreamTests2) isolate old cases below and above the upgraded ones, and one (NewStreamTests) are the updated ones themselves. The reason is because subclassing from both old test_utils.TestCase and new unittest.IsolatedAsyncioTestCase leads to conflicts aborting each test with RuntimeError: cannot enter context: <...> is already entered.

@bedevere-bot bedevere-bot added tests Tests in the Lib/test dir awaiting review labels May 31, 2022
@arhadthedev
Copy link
Member Author

I've made a rewrite of description for both the PR and the issue to explain a target more clearly.

@gvanrossum gvanrossum self-requested a review as a code owner September 27, 2022 17:48
@gvanrossum
Copy link
Member

This is a bit difficult to review since there is a lot of code being refactored. But I will give it a try (is there any other asyncio expert who is interested?).

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I forgot to click "Submit" :)

# See http://bugs.python.org/issue35065
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
Copy link
Member

Choose a reason for hiding this comment

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

Looks like .set_exception_handler is now missing from this test. Is it fine?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I've removed all usages of messages inter-thread communication list:

  1. -        messages = []
    -        self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
  2. -        self.assertEqual(messages, [])

because the server is now async, lives in a main thread, and needs no intermediary to pass exceptions into a test harness.

Copy link
Member Author

Choose a reason for hiding this comment

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

By the way, thank you for noticing, I've added the clarification as the second paragraph of the first PR comment.

Copy link
Member

@gvanrossum gvanrossum 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've skimmed the code and it looks fine to me. Together with the expert reviews you've already received and addressed I think it's ready to merge.

I've read your full plan and once this lands please go ahead with the next steps!

@gvanrossum gvanrossum merged commit ce8fc18 into python:main Oct 4, 2022
@arhadthedev arhadthedev deleted the teststreams-utilsTestCase-servers branch October 4, 2022 17:57
@kumaraditya303
Copy link
Contributor

@arhadthedev
Copy link
Member Author

@kumaraditya303 Thank you for reporting; I'm investigating now to fix it ASAP.

@gvanrossum
Copy link
Member

Okay, give us updates as you go along -- IIRC the custom is to revert if no fix has been seen within 24 hours.

@gvanrossum
Copy link
Member

FWIW my guess would be that you can't actually use async def test_blah(self) in a class derived from test_utils.TestCase.

@arhadthedev
Copy link
Member Author

arhadthedev commented Oct 5, 2022

@gvanrossum I've created gh-97896 to fix the break. I'm sorry for the delay; initially I wanted to undo the affected lines but then I ended up with wrapping them into another IsolatedAsyncioTestCase thus making the affected tests async along with three more in-between.

Probably, OpenSSL runs need to be included into the mandatory checks to avoid such accidental oversights later. Edit: I looked into the log under #93369 (comment); the failed tests seem to be skipped until a PR is merged. Can we resolve the problem by making in-PR runs to fail on warnings like after-merge ones do?

@gvanrossum
Copy link
Member

There's a script that runs all the tests that depend on openssl, turning warnings into errors. I ran it manually like this:

./python.exe -m test.ssltests

I agree this ought to be part of the standard CI run, this has bitten me multiple times.

@sobolevn
Copy link
Member

sobolevn commented Oct 5, 2022

I agree this ought to be part of the standard CI run, this has bitten me multiple times.

I will open a new issue for it!

arhadthedev added a commit to arhadthedev/cpython that referenced this pull request Oct 7, 2022
gvanrossum pushed a commit that referenced this pull request Oct 7, 2022
…_streams: port server cases to IsolatedAsyncioTestCase" (#98015)

This PR reverts gh-93369 and gh-97896 because they've made asyncio tests unstable. After these PRs were merged, random GitHub action jobs of random commits started to fail unrelated tests and test framework methods.

The reverting is necessary because such shrapnel failures are a symptom of some underlying bug that must be found and fixed first.

I had a hope that it's a server overload because we already have extremely rare disc access errors. However, one and a half day passed, and the failures continue to emerge both in PRs and commits.

Affected issue: gh-93357.
First reported in #97940 (comment).

* Revert "gh-93357: Port test cases to IsolatedAsyncioTestCase, part 2 (#97896)"

This reverts commit 09aea94.

* Revert "gh-93357: Start porting asyncio server test cases to IsolatedAsyncioTestCase (#93369)"

This reverts commit ce8fc18.
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
…yncioTestCase (python#93369)

Lay the foundation for further work in `asyncio.test_streams`.
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
…o.test_streams: port server cases to IsolatedAsyncioTestCase" (python#98015)

This PR reverts pythongh-93369 and pythongh-97896 because they've made asyncio tests unstable. After these PRs were merged, random GitHub action jobs of random commits started to fail unrelated tests and test framework methods.

The reverting is necessary because such shrapnel failures are a symptom of some underlying bug that must be found and fixed first.

I had a hope that it's a server overload because we already have extremely rare disc access errors. However, one and a half day passed, and the failures continue to emerge both in PRs and commits.

Affected issue: pythongh-93357.
First reported in python#97940 (comment).

* Revert "pythongh-93357: Port test cases to IsolatedAsyncioTestCase, part 2 (python#97896)"

This reverts commit 09aea94.

* Revert "pythongh-93357: Start porting asyncio server test cases to IsolatedAsyncioTestCase (python#93369)"

This reverts commit ce8fc18.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir topic-asyncio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants