Skip to content

Convert some async TestCase code to coroutines #12375

Merged
adiroiban merged 11 commits intotwisted:trunkfrom
p12tic:cleanup-asynctest
Dec 22, 2024
Merged

Convert some async TestCase code to coroutines #12375
adiroiban merged 11 commits intotwisted:trunkfrom
p12tic:cleanup-asynctest

Conversation

@p12tic
Copy link
Contributor

@p12tic p12tic commented Nov 25, 2024

This PR cleans up some asynchronous TestCase code. Previous code was relatively hard to follow due to it relying on callbacks based implementation, which forced the logic to be split across many small functions. The new code puts everything into regular code flow across several functions and uses standard try...except and try...finally for error handling.

The code would be even simplier if IReporter.addError supported regular exceptions, but this is for a future.

The PR has been split across many small commits so that it is possible to bisect the changes in the future if there are any bugs that may be caused by this PR. Also, review should be easier, as the changes in isolation are almost trivial.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 25, 2024

CodSpeed Performance Report

Merging #12375 will degrade performances by 3.67%

Comparing p12tic:cleanup-asynctest (11d3e5b) with trunk (f5b49ab)

Summary

⚡ 2 improvements
❌ 1 regressions
✅ 31 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark trunk p12tic:cleanup-asynctest Change
test_tcp_throughput 5.1 ms 5.3 ms -3.67%
test_main_method[testPlain] 1.2 ms 1.1 ms +2.04%
test_setup_teardown[BenchmarkTestsSetUpTearDownPlain] 1.1 ms 1.1 ms +2.07%

@p12tic
Copy link
Contributor Author

p12tic commented Dec 6, 2024

please review

Copy link
Member

@adiroiban adiroiban 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 cleanup and sorry for the delay in reviewing.

The changes looks good.

My only concern is about removign the public method.

@p12tic
Copy link
Contributor Author

p12tic commented Dec 8, 2024

With rejection of #12387 I don't think this PR has benefits, therefore I'm closing it.

@twm
Copy link
Member

twm commented Dec 9, 2024

I wish we had some benchmarks here, because I wonder if this speed up Trial tests (which would be very much worthwhile!).

@p12tic
Copy link
Contributor Author

p12tic commented Dec 9, 2024

Benchmarks have been added in #12393. On my machine I see improvement of around 2%, so probably it makes sense to land this PR still.

@p12tic
Copy link
Contributor Author

p12tic commented Dec 18, 2024

@adiroiban I have addressed all your comments.

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the refactoring.

Only a minor comment.

@adiroiban adiroiban merged commit 11d78fd into twisted:trunk Dec 22, 2024
@p12tic p12tic deleted the cleanup-asynctest branch December 22, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants