test: Fix flaky full-stack tests by randomizing base ports#7244
Draft
okurz wants to merge 1 commit intoos-autoinst:masterfrom
Draft
test: Fix flaky full-stack tests by randomizing base ports#7244okurz wants to merge 1 commit intoos-autoinst:masterfrom
okurz wants to merge 1 commit intoos-autoinst:masterfrom
Conversation
Motivation: Multiple full-stack tests were failing intermittently when run in parallel due to "Address already in use" errors. They all defaulted to the same base port (9526), causing conflicts in concurrent test environments. Design Choices: - Introduced `setup_random_base_port` helper in `OpenQA::Test::Utils` to centralize randomization logic. - Applied `setup_random_base_port` to `t/05-scheduler-full.t`, `t/25-cache-service.t`, `t/33-developer_mode.t`, `t/43-scheduling-and-worker-scalability.t`, and `t/full-stack.t`. - Uses `20000 + int rand 10000` to pick a likely-free port range. - The helper uses `||=` to allow overriding via environment variables. - Removed duplicate randomization logic and redundant comments across multiple test files. - Cleaned up `BEGIN` blocks and imports in full-stack tests. Benefits: - Eliminates port conflicts during parallel test execution. - Improves test stability and reliability for CI/CD. - Centralizes logic for easier future maintenance and consistent port selection strategy. - Cleaner and more maintainable test code.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7244 +/- ##
=======================================
Coverage 99.90% 99.90%
=======================================
Files 419 419
Lines 43983 43997 +14
=======================================
+ Hits 43942 43956 +14
Misses 41 41 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
perlpunk
reviewed
Apr 2, 2026
| # reuse it in listen to prevent race condition | ||
| # | ||
| # Potentially this approach can also be used in production code. | ||
| sub setup_random_base_port { |
Contributor
There was a problem hiding this comment.
Now I'm wondering why mock_service_ports was removed: 8d7b9a5
I guess the according comment block was overlooked.
Member
Author
There was a problem hiding this comment.
huh. That's why this comment block was a bit dangling :D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
Multiple full-stack tests were failing intermittently when run in parallel
due to "Address already in use" errors. They all defaulted to the same
base port (9526), causing conflicts in concurrent test environments.
Design Choices:
setup_random_base_porthelper inOpenQA::Test::Utilsto centralize randomization logic.
setup_random_base_porttot/05-scheduler-full.t,t/25-cache-service.t,t/33-developer_mode.t,t/43-scheduling-and-worker-scalability.t, andt/full-stack.t.20000 + int rand 10000to pick a likely-free port range.||=to allow overriding via environment variables.multiple test files.
BEGINblocks and imports in full-stack tests.Benefits:
port selection strategy.