Skip to content

Commit

Permalink
#25 - Modify FileWatchTest for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Dec 15, 2021
1 parent 48359ad commit 1d295db
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/test/java/io/avaje/config/FileWatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,34 @@ void test_check_whenTouchedScheduled_expect_loaded() {

@Test
void test_check_whenFileWritten() throws Exception {
log.info("test_check_whenFileWritten");
CoreConfiguration config = newConfig();
List<File> files = files();

final FileWatch watch = new FileWatch(config, files, new YamlLoaderSnake());
touchFiles(files);
watch.check();

if (isGithubActions()) {
File aFile = files.get(0);
log.info("file change detection in GithubActions via change in length from {}", aFile.length());
assertThat(config.get("one", null)).isEqualTo("a");
writeContent("one=NotA");
assertThat(config.get("one", null)).isNull();

writeContent("one=NotAReally");
sleep(20);
log.info("file length now {}", aFile.length());
watch.check();
assertThat(config.get("one", null)).isEqualTo("NotAReally");

writeContent("one=a");
sleep(20);
log.info("file length now {}", aFile.length());
watch.check();
assertThat(config.get("one", null)).isEqualTo("NotA");
assertThat(config.get("one", null)).isEqualTo("a");
return;
}

touchFiles(files);
watch.check();

// properties loaded as expected
final int size0 = config.size();
assertThat(size0).isGreaterThan(2);
Expand All @@ -132,11 +142,10 @@ private void writeContent(String content) throws IOException {
}
FileWriter fw = new FileWriter(aProps);
fw.write(content);
fw.flush();
fw.close();
if (!aProps.setLastModified(System.currentTimeMillis())) {
System.err.println("setLastModified not successful");
}
// if (!aProps.setLastModified(System.currentTimeMillis())) {
// System.err.println("setLastModified not successful");
// }
}

private void sleep(int millis) {
Expand Down

0 comments on commit 1d295db

Please sign in to comment.