Skip to content

Commit

Permalink
Fix FileWatcher test case
Browse files Browse the repository at this point in the history
Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Nov 13, 2022
1 parent 67ce7c8 commit be12831
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit be12831

Please sign in to comment.