Skip to content

Commit

Permalink
Fix RepositoryAnalysisFailureIT (#95046)
Browse files Browse the repository at this point in the history
This test is supposed to trigger a failure by exposing a spurious value
for the register, but sometimes it exposes `expectedMax` which is what
we expect at the end of the register checks. With this commit we ensure
that we don't inadvertently return a correct value.

Closes #94410
  • Loading branch information
DaveCTurner authored Apr 5, 2023
1 parent c6bb109 commit 3f6d8ab
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,19 @@ public void testFailsIfRegisterHoldsSpuriousValue() {
@Override
public long onCompareAndExchange(AtomicLong register, long expected, long updated) {
if (randomBoolean() && sawSpuriousValue.compareAndSet(false, true)) {
return randomFrom(expectedMax, randomLongBetween(expectedMax, Long.MAX_VALUE), randomLongBetween(Long.MIN_VALUE, -1));
if (register.get() == expectedMax) {
return randomFrom(
randomLongBetween(0L, expectedMax - 1),
randomLongBetween(expectedMax + 1, Long.MAX_VALUE),
randomLongBetween(Long.MIN_VALUE, -1)
);
} else {
return randomFrom(
expectedMax,
randomLongBetween(expectedMax, Long.MAX_VALUE),
randomLongBetween(Long.MIN_VALUE, -1)
);
}
}
return register.compareAndExchange(expected, updated);
}
Expand Down

0 comments on commit 3f6d8ab

Please sign in to comment.