Skip to content

Improve speed of running tests #1218

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

Merged
merged 5 commits into from
Nov 26, 2022
Merged

Improve speed of running tests #1218

merged 5 commits into from
Nov 26, 2022

Conversation

bkoelman
Copy link
Member

@bkoelman bkoelman commented Nov 12, 2022

This PR activates async throttling of integration tests (instead of reducing parallelism in xUnit, which is what we had before). It uses the approach described at xunit/xunit#2003 (comment).

Throttling is needed to avoid PostgreSQL failing because the maximum number of open connections has been reached (100 by default). As an alternative for throttling, I've tried increasing the max connections limit to 1000 and 500, but without much success.

I've experimented with various throttling thresholds and found a good balance at 64, which leaves some room for abandoned connections (when hard-killing tests during development and debugging). Watching the database server with pgAdmin while running tests, I didn't see more than ~50 temporary databases simultaneously. Measurements confirm that setting the threshold higher doesn't provide measurable gain.

In addition, all models in integration tests now use DeleteBehavior.SetNull instead of DeleteBehavior.ClientSetNull, so that PostgreSQL performs the related deletes on the database server. That's not only more reliable but also more efficient; it shaves off another ~5 seconds.

Running all tests on my computer with:

git clean -xdf ; dotnet build
Measure-Command { dotnet test --no-build | Out-Default }

This yields the following results:

system master (sec) PR (sec) %
local 96 45 46%
AppVeyor Windows 209 221 106%
AppVeyor Linux 239 195 82%

Conclusion: this makes running our tests twice as fast locally! The duration of cibuilds varies wildly, so measurements are not very reliable to compare. Also, their VMs have fewer cores, possibly resulting in more context switches.

QUALITY CHECKLIST

…ior.ClientSetNull to DeleteBehavior.SetNull

This improves speed and reduces the number of errors logged by the PostgreSQL server when running tests, because we no longer need the "truncate table cascade" fallback in DbContextExtensions.
@codecov
Copy link

codecov bot commented Nov 12, 2022

Codecov Report

Merging #1218 (7cdf273) into master (c14637c) will decrease coverage by 0.06%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1218      +/-   ##
==========================================
- Coverage   92.69%   92.62%   -0.07%     
==========================================
  Files         243      243              
  Lines        7799     7799              
==========================================
- Hits         7229     7224       -5     
- Misses        570      575       +5     
Impacted Files Coverage Δ
...Core/Repositories/EntityFrameworkCoreRepository.cs 97.61% <0.00%> (-1.71%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bkoelman bkoelman requested a review from maurei November 12, 2022 20:38
@bkoelman bkoelman marked this pull request as ready for review November 12, 2022 20:39
@bkoelman
Copy link
Member Author

@maurei Can you check on MacOS whether tests still succeed and if/how it improves testrun duration?

@maurei maurei merged commit afa80e8 into master Nov 26, 2022
@maurei maurei deleted the xunit-perf-throttling branch November 26, 2022 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants