Skip to content

Emit warning when using --shard-count (> 1) with --order rand - #3186

Merged
horenmar merged 1 commit into
catchorg:develfrom
mattyrazz7:bugfix/warn-on-sharding-with-rand
Aug 10, 2026
Merged

Emit warning when using --shard-count (> 1) with --order rand#3186
horenmar merged 1 commit into
catchorg:develfrom
mattyrazz7:bugfix/warn-on-sharding-with-rand

Conversation

@mattyrazz7

Copy link
Copy Markdown
Contributor

Description

Using sharding with the default test ordering (--order rand) doesn't behave properly since each --shard-index invocation obtains a freshly reordered set, resulting in duplication and omitted tests. This can be fixed by changing the test ordering or using a fixed random seed between invocations, but it's surprising default behavior.

Change

Mitigate by emitting a warning when the following conditions are met:

  • --shard-count > 1
  • AND --order is rand
  • AND --rng-seed is set to time or random-device

The warning points users to either set --order decl, --order lex, or pass a fixed value to --rng-seed.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.24%. Comparing base (4cde128) to head (126c88a).

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3186      +/-   ##
==========================================
- Coverage   91.25%   91.24%   -0.01%     
==========================================
  Files         204      204              
  Lines        8965     8973       +8     
==========================================
+ Hits         8181     8187       +6     
- Misses        784      786       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mattyrazz7
mattyrazz7 force-pushed the bugfix/warn-on-sharding-with-rand branch from 44dc3cc to 0aad6b3 Compare July 31, 2026 20:01
Comment thread tests/ExtraTests/CMakeLists.txt Outdated
)
set_tests_properties(TestSharding::NoWarningOnRandomOrderWithFixedSeed
PROPERTIES
FAIL_REGULAR_EXPRESSION "Warning: using sharding \\(--shard-count\\) with random order"

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 should be more generic (less specific), so that small rewording of the err. message doesn't break it.

Or have it be a CMake variable that is used by this & and the test above, so that the two tests are guaranteed to be kept in sync.

Comment thread tests/CMakeLists.txt Outdated
set_tests_properties(TestSharding::NoWarningOnRandomOrderWithFixedSeed
PROPERTIES
FAIL_REGULAR_EXPRESSION "Warning: using sharding \\(--shard-count\\) with random order"
)

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.

There should also be a test that the warning doesn't fire without rng-seed, but with declaration/alphabetical order.

@horenmar

horenmar commented Aug 2, 2026

Copy link
Copy Markdown
Member

Thanks, this will be useful.

@mattyrazz7
mattyrazz7 force-pushed the bugfix/warn-on-sharding-with-rand branch from 0aad6b3 to b9283fd Compare August 2, 2026 16:27
Comment thread tests/CMakeLists.txt Outdated
PROPERTIES
FAIL_REGULAR_EXPRESSION "${CATCH_SHARDING_WARNING_REGEX}"
)
endforeach()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used a loop to test both lex and decl, but let me know if you want me to do it another way

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.

That's fine

Comment thread tests/CMakeLists.txt Outdated
PASS_REGULAR_EXPRESSION "Randomness seeded to: 17171717"
)

set(CATCH_SHARDING_WARNING_REGEX "Warning: using sharding .* with random order")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Went with this to give us more flexibility while still getting the gist of the message

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.

Sure

@horenmar

horenmar commented Aug 4, 2026

Copy link
Copy Markdown
Member
  1. Move the tests down into ExtraTests
  2. Check what the CI is telling you ;-)
  3. Fix it

@mattyrazz7
mattyrazz7 force-pushed the bugfix/warn-on-sharding-with-rand branch 2 times, most recently from 0749a82 to 6ac51cd Compare August 8, 2026 13:06
@mattyrazz7
mattyrazz7 force-pushed the bugfix/warn-on-sharding-with-rand branch from 6ac51cd to 126c88a Compare August 9, 2026 05:04
@mattyrazz7

Copy link
Copy Markdown
Contributor Author
  1. Move the tests down into ExtraTests

    1. Check what the CI is telling you ;-)

    2. Fix it

Sorry for the delay, updated

@horenmar
horenmar merged commit 0aeb818 into catchorg:devel Aug 10, 2026
88 checks passed
@horenmar

Copy link
Copy Markdown
Member

Thanks

@mattyrazz7
mattyrazz7 deleted the bugfix/warn-on-sharding-with-rand branch August 14, 2026 22:37
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