Skip to content

tests: actually randomise the order of tests#1613

Merged
phkahler merged 1 commit intosolvespace:masterfrom
iscgar:iscgar/randomise-test-order
Aug 13, 2025
Merged

tests: actually randomise the order of tests#1613
phkahler merged 1 commit intosolvespace:masterfrom
iscgar:iscgar/randomise-test-order

Conversation

@iscgar
Copy link
Contributor

@iscgar iscgar commented Aug 9, 2025

std::random_shuffle can use std::rand (and does so on Windows), and without intialising with srand() the order will always be the same, so we don't get the expected randomisation.

Switch to using std::shuffle with a proper random number generator in order to fix this and get random order execution.

@iscgar iscgar force-pushed the iscgar/randomise-test-order branch from d7ccf34 to 93ea9eb Compare August 10, 2025 20:53
@phkahler
Copy link
Member

This is kind of a bad idea. If a test fails because of running in a particular order, then random failures will not be reproducible.

@ruevs
Copy link
Member

ruevs commented Aug 11, 2025

This is kind of a bad idea. If a test fails because of running in a particular order, then random failures will not be reproducible.

Indeed. The tests should use a P(seudo)RNG (not a T(rue)RNG).

If the tests are to run with a different seed of the PRNG each time (in principle not a bad idea) then this seed should be displayed (to be logged during test runs) so that if the tests fail with a particular seed the failure can be reproduced.

@iscgar
Copy link
Contributor Author

iscgar commented Aug 11, 2025

The Mersenne Twister is still a PRNG, just seeded from what might be a true random (not required by the standard). The original code always had a deterministic order because the RNG wasn't seeded, so the shuffle did nothing. If we're after reproducibility, I can just print the seed and add an option to supply a seed for running the tests to make it reproducible. Would that be acceptable?

@phkahler
Copy link
Member

@iscgar Yes, printing the seed should make failures reproducible.

@iscgar iscgar force-pushed the iscgar/randomise-test-order branch from 93ea9eb to 511f6a6 Compare August 11, 2025 20:40
@iscgar
Copy link
Contributor Author

iscgar commented Aug 11, 2025

Done.

filter = args[1];
filterPattern = args[1];
} else if(args.size() == 3) {
seed = std::stoul(args[2]);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
seed = std::stoul(args[2]);
filterPattern = args[1];
seed = std::stoul(args[2]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks! Fixed.

`std::random_shuffle` can use `std::rand` (and does so on Windows), and
without intialising with `srand()` the order will always be the same, so
we don't get the expected randomisation.

Switch to using `std::shuffle` with a proper random number generator in
order to fix this and get random order execution.
@iscgar iscgar force-pushed the iscgar/randomise-test-order branch from 511f6a6 to fefce40 Compare August 12, 2025 19:51
@ruevs
Copy link
Member

ruevs commented Aug 13, 2025

I'm fine with this. @phkahler ?

@phkahler phkahler merged commit 74a13ef into solvespace:master Aug 13, 2025
4 checks passed
@iscgar iscgar deleted the iscgar/randomise-test-order branch August 18, 2025 08:14
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.

3 participants