Skip to content

Conversation

@arrayka
Copy link
Contributor

@arrayka arrayka commented Jan 26, 2026

Why

  • The test_compute_relative_contrast_with_random_data() test still fails intermittently because average_squared_distance() internally creates its own RNG using random::create_rnd().
  • In test mode, we expect random::create_rnd() to produce a deterministic, seeded RNG. However, the function is compiled in dev mode rather than test mode, so it doesn’t behave deterministically, leading to flaky test behavior.

What

  • Pass an RNG instance into average_squared_distance() so the caller (including tests) can inject a deterministic RNG.
  • [Optional] Update random::create_rnd() so that when compiled with feature = "testing", it returns a seeded, deterministic RNG.

Now, multiple runs of the test produce the same output:

Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035
Mean relative contrast: 1.1806035

@arrayka arrayka requested a review from hildebrandmw January 26, 2026 21:45
@arrayka arrayka merged commit 33a6c5d into main Jan 26, 2026
22 of 29 checks passed
@arrayka arrayka deleted the u/arrayka/fix_flaky_test branch January 26, 2026 22:58
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