Skip to content

Speed up test_starttls.py::TestTLSEnding::test_eof_received#587

Open
cuu508 wants to merge 1 commit into
aio-libs:masterfrom
cuu508:simplify_test_eof_received
Open

Speed up test_starttls.py::TestTLSEnding::test_eof_received#587
cuu508 wants to merge 1 commit into
aio-libs:masterfrom
cuu508:simplify_test_eof_received

Conversation

@cuu508

@cuu508 cuu508 commented May 8, 2026

Copy link
Copy Markdown
Contributor

What do these changes do?

It fixes a 30 second delay in aiosmtpd/tests/test_starttls.py::TestTLSEnding::test_eof_received.

The contents of the test case was wrapped in try ... finally, and the finally block runs tls_controller.stop(). The finally block is where the 30 seconds were spent.

The tls_controller is prepared by a pytest fixture which also takes care of closing it so I suspect the finally block was not doing anything useful anyway.

After removing try .. finally tests on all platforms still pass, and the 30 second delay is gone.

Are there changes in behavior for the user?

No, it speeds up a single slow test.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • tox testenvs have been executed in the following environments:
    • Linux (Ubuntu 18.04, Ubuntu 20.04, Arch): {py36,py37,py38,py39}-{nocov,cov,diffcov}, qa, docs
    • Windows (7, 10): {py36,py37,py38,py39}-{nocov,cov,diffcov}
    • WSL 1.0 (Ubuntu 18.04): {py36,py37,py38,py39}-{nocov,cov,diffcov}, pypy3-{nocov,cov}, qa, docs
    • FreeBSD (12.2, 12.1, 11.4): {py36,pypy3}-{nocov,cov,diffcov}, qa
    • Cygwin: py36-{nocov,cov,diffcov}, qa, docs
  • Documentation reflects the changes
  • Add a news fragment into the NEWS.rst file

@cuu508 cuu508 changed the title Remove try .. finally which does not appear to be needed Speed up test_starttls.py::TestTLSEnding::test_eof_received May 8, 2026
@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.78%. Comparing base (c37e362) to head (1bfefba).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #587      +/-   ##
==========================================
+ Coverage   97.75%   97.78%   +0.03%     
==========================================
  Files          23       23              
  Lines        5700     5698       -2     
  Branches      351      351              
==========================================
  Hits         5572     5572              
+ Misses         79       77       -2     
  Partials       49       49              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 214 to 219
# I don't like this. It's too intimately involved with the innards of the SMTP
# class. But for the life of me, I can't figure out why coverage there fail
# intermittently.
#
# I suspect it's a race condition, but with what, and how to prevent that from
# happening, that's ... a mystery.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a part of the puzzle?

Comment on lines 73 to 75
# Some test cases need to .stop() the controller inside themselves
# in such cases, we must suppress Controller's raise of AssertionError
# because Controller doesn't like .stop() to be invoked more than once

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this refer to the thing you're removing? Are there any other in-test stops?

# happening, that's ... a mystery.

# Entering portion of code where hang is possible (upon assertion fail), so
# we must wrap with "try..finally".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you checked git blame for clues?

@webknjaz

webknjaz commented Jul 1, 2026

Copy link
Copy Markdown
Member

After removing try .. finally tests on all platforms still pass, and the 30 second delay is gone.

It's possible that certain patch versions would reproduce it. Have you built like every Python 3.9.x with pyenv to confirm? This is likely hitting one of the cases that we don't test in CI or maybe something flaky that only happens under mysterious circumstances.

Overall, the cleanup idea seems good, but I'd also like to hear a second opinion from @loqs at least..

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.

2 participants