Skip to content

Commit 0b4c68c

Browse files
committed
test: Assert that the file data poller goes quiet once a file is stable
A plain rewrite is not atomic: the write and the modification-time update are separate steps, and a poll that lands between them legitimately reports an extra change. The poller promises generous detection, not one callback per logical change; the reloader coalesces and skips the excess. The test that expected exactly one callback could therefore fail on a busy machine. It now waits for the write to be fully observed and then requires that the count stays put, which still fails for a poller that does not update its baseline.
1 parent 8edc7db commit 0b4c68c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/integrations/FileDataPollerTest.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class FileDataPollerTest {
3030
private static final Duration INTERVAL = Duration.ofMillis(20);
3131
private static final long WAIT_MILLIS = 5000;
3232
private static final long QUIET_MILLIS = 250;
33+
// Long enough for a rewrite that the poller observed in several steps to be fully reported.
34+
private static final long SETTLE_MILLIS = 100;
3335

3436
private static void awaitCount(AtomicInteger counter, int expected) throws InterruptedException {
3537
long deadline = System.currentTimeMillis() + WAIT_MILLIS;
@@ -80,16 +82,21 @@ public void detectsSizeChangeWithSameModifiedTime() throws Exception {
8082
}
8183
}
8284

85+
// The poller updates its baseline after a change, so it goes quiet once the file is stable. It
86+
// does not promise one callback per logical change: a rewrite is not atomic, and a poll that
87+
// lands between its steps legitimately reports an extra change, which the reloader absorbs.
8388
@Test
84-
public void firesOncePerChange() throws Exception {
89+
public void stopsFiringWhenFileIsStable() throws Exception {
8590
try (TempDir dir = TempDir.create()) {
8691
Path file = createFile(dir, "a.json", "{}", 1000_000);
8792
AtomicInteger changes = new AtomicInteger();
8893
try (FileDataPoller poller = new FileDataPoller(Collections.singletonList(file), INTERVAL, changes::incrementAndGet, testLogger)) {
8994
rewrite(file, "{}", 2000_000);
9095
awaitCount(changes, 1);
96+
Thread.sleep(SETTLE_MILLIS);
97+
int settled = changes.get();
9198
Thread.sleep(QUIET_MILLIS);
92-
assertEquals(1, changes.get());
99+
assertEquals(settled, changes.get());
93100
}
94101
}
95102
}

0 commit comments

Comments
 (0)