-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Describe the bug
The unit test PredictRating_WithOtherUserHavingRatedTargetItem_ShouldCalculateSimilarityAndWeightedSum
occasionally fails even though the logic and expected values are correct. The behavior is non-deterministic — it sometimes passes, sometimes fails.
To Reproduce
- Run the test suite multiple times (Run ALL unit tests, not only it)
- Observe that
PredictRating_WithOtherUserHavingRatedTargetItem_ShouldCalculateSimilarityAndWeightedSum
sometimes fails randomly
Expected behavior
- The field should consistently reference the injected dependency.
- The test should deterministically pass when the mock returns fixed values.
Actual behavior
- Test passes intermittently.
- When the mock reference is lost (null), similarity calculations fall back to undefined behavior.
Root cause
This test class used fixture-level fields (e.g., the ISimilarityCalculator
mock, the CollaborativeFiltering
instance, and the ratings data) that were re-initialized in [SetUp]
. When the whole test suite runs (often in parallel), another test’s [SetUp]
can overwrite those fields while this test is executing
=> Shared mutable test state + parallel execution = race condition.
siriak