Skip to content

Commit 2e71daa

Browse files
committed
fix: de-flake LatestDistinctIT.java
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 2cfe804 commit 2e71daa

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/latestdistinct/LatestDistinctIT.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,28 @@ void testLatestDistinctListWithTwoInformerEventSources() {
7676
// Should see 1 distinct ConfigMaps
7777
assertThat(updatedResource.getStatus().getConfigMapCount()).isEqualTo(1);
7878
assertThat(reconciler.isErrorOccurred()).isFalse();
79-
// note that since there are two event source, and we do the update through one event
80-
// source
81-
// the other will still propagate an event
82-
assertThat(reconciler.getNumberOfExecutions()).isEqualTo(2);
79+
// Since there are two event sources and we do the update through one of them, the
80+
// other source still propagates an event, triggering at least a second
81+
// reconciliation. The exact count is not asserted: the initial ADDED event fires from
82+
// both informers and only usually coalesces into a single reconciliation, so an
83+
// occasional extra reconciliation is an expected, benign event-coalescing race.
84+
assertThat(reconciler.getNumberOfExecutions()).isGreaterThanOrEqualTo(2);
85+
});
86+
87+
// Stabilization check: with correct own-update filtering the reconciler's own ConfigMap update
88+
// must not trigger a fresh reconciliation, so the execution count has to settle. A runaway
89+
// reconcile loop (filtering broken) would keep incrementing it. We allow one in-flight
90+
// reconciliation past the baseline but require the count to stop growing over the window.
91+
int executionsBaseline = reconciler.getNumberOfExecutions();
92+
await()
93+
.during(Duration.ofSeconds(2))
94+
.atMost(Duration.ofSeconds(3))
95+
.untilAsserted(
96+
() -> {
97+
assertThat(reconciler.isErrorOccurred()).isFalse();
98+
assertThat(reconciler.getNumberOfExecutions())
99+
.as("reconciliation count must stabilize, not loop")
100+
.isLessThanOrEqualTo(executionsBaseline + 1);
83101
});
84102
}
85103

0 commit comments

Comments
 (0)