diff --git a/utils/src/test/scala/com/reactific/riddl/utils/FileWatcherTest.scala b/utils/src/test/scala/com/reactific/riddl/utils/FileWatcherTest.scala index 10cc95d22..0e3a89de2 100644 --- a/utils/src/test/scala/com/reactific/riddl/utils/FileWatcherTest.scala +++ b/utils/src/test/scala/com/reactific/riddl/utils/FileWatcherTest.scala @@ -17,24 +17,27 @@ class FileWatcherTest extends AnyWordSpec with Matchers { val dir = Path.of(".").resolve("onchange").resolve("target") .toAbsolutePath def onEvents(events: Seq[WatchEvent[?]]): Boolean = { - info(s"Event: ${events.mkString(",")}") + events.foreach { ev => info(s"Event: ${ev.kind()}: ${ev.count()}") } false } def notOnEvents: Boolean = { info("No events") true } + // Resolve the file to + val changeFile = dir.resolve("change.file") + // Make sure it doesn't exist + if (Files.exists(changeFile)) { Files.delete(changeFile) } // watch for changes val f = Future[Boolean] { FileWatcher.watchForChanges(dir, 2, 10)(onEvents)(notOnEvents) } - Thread.sleep(1000) - val changeFile = dir.resolve("change.file") - if (Files.exists(changeFile)) { Files.delete(changeFile) } - changeFile.toFile.createNewFile() + Thread.sleep(900) + Files.createFile(changeFile) + require(Files.exists(changeFile), "File should exist") + Thread.sleep(100) Files.delete(changeFile) - info(s"Future completed: ${f.isCompleted}") - val result = Await.result(f, Duration(1, "seconds")) + val result = Await.result(f, Duration(3, "seconds")) result must be(true) } }