Skip to content

Commit 21e1592

Browse files
committed
Add delay to fix test (indexingRescanOnOverflow in SingleDirectoryTests)
1 parent 2a69238 commit 21e1592

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/test/java/engineering/swat/watch/SingleDirectoryTests.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,13 @@ void indexingRescanOnOverflow() throws IOException, InterruptedException {
175175
.on(bookkeeper);
176176

177177
try (var watch = watchConfig.start()) {
178-
179178
// Begin overflow simulation
180179
dropEvents.set(true);
181180

182-
// Do some file operations. No events should be observed (because
183-
// the overflow simulation is running).
181+
// Perform some file operations (after a short wait to ensure a new
182+
// last-modified-time). No events should be observed (because the
183+
// overflow simulation is running).
184+
Thread.sleep(TestHelper.SHORT_WAIT.toMillis());
184185
Files.writeString(directory.resolve("a.txt"), "foo");
185186
Files.writeString(directory.resolve("b.txt"), "bar");
186187
Files.delete(directory.resolve("c.txt"));
@@ -206,25 +207,28 @@ void indexingRescanOnOverflow() throws IOException, InterruptedException {
206207
.until(() -> bookkeeper.events().any(e));
207208
}
208209

209-
// Do some more file operations. All events should be observed
210-
// (because the overflow simulation is no longer running).
211210
bookkeeper.reset();
211+
212+
// Perform some more file operations. All events should be observed
213+
// (because the overflow simulation is no longer running).
214+
Thread.sleep(TestHelper.SHORT_WAIT.toMillis());
215+
Files.delete(directory.resolve("a.txt"));
212216
Files.writeString(directory.resolve("b.txt"), "baz");
213217
Files.createFile(directory.resolve("c.txt"));
214-
Files.delete(directory.resolve("d.txt"));
215218

216219
for (var e : new WatchEvent[] {
220+
new WatchEvent(DELETED, directory, Path.of("a.txt")),
217221
new WatchEvent(MODIFIED, directory, Path.of("b.txt")),
218-
new WatchEvent(CREATED, directory, Path.of("c.txt")),
219-
new WatchEvent(DELETED, directory, Path.of("d.txt"))
222+
new WatchEvent(CREATED, directory, Path.of("c.txt"))
220223
}) {
221224
await("File operation should trigger event: " + e)
222225
.until(() -> bookkeeper.events().any(e));
223226
}
224227

228+
bookkeeper.reset();
229+
225230
// Generate another `OVERFLOW` event. Synthetic events shouldn't be
226231
// issued and observed (because the index should have been updated).
227-
bookkeeper.reset();
228232
((EventHandlingWatch) watch).handleEvent(overflow);
229233

230234
await("No events should have been triggered")

0 commit comments

Comments
 (0)