NIFI-12019 Improved reliability of TestSynchronousFileWatcher

This closes #7770

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Mike Moser 2023-09-21 16:55:54 +00:00 committed by exceptionfactory
parent 9b591a2fe3
commit 1f87c16ab8
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
1 changed files with 2 additions and 7 deletions

View File

@ -37,9 +37,8 @@ public class TestSynchronousFileWatcher {
Files.copy(new ByteArrayInputStream("Hello, World!".getBytes("UTF-8")), path, StandardCopyOption.REPLACE_EXISTING);
final UpdateMonitor monitor = new DigestUpdateMonitor();
final SynchronousFileWatcher watcher = new SynchronousFileWatcher(path, monitor, 40L);
final SynchronousFileWatcher watcher = new SynchronousFileWatcher(path, monitor, 0L);
assertFalse(watcher.checkAndReset());
Thread.sleep(41L);
assertFalse(watcher.checkAndReset());
try (FileOutputStream fos = new FileOutputStream(path.toFile())) {
@ -47,11 +46,7 @@ public class TestSynchronousFileWatcher {
fos.getFD().sync();
}
// immediately after file changes, but before the next check time is reached, answer should be false
assertFalse(watcher.checkAndReset());
// after check time has passed, answer should be true
Thread.sleep(41L);
// file has changed, answer should be true once
assertTrue(watcher.checkAndReset());
assertFalse(watcher.checkAndReset());
}