Skip to content

Commit

Permalink
Fix file settings service test on windows (elastic#115234)
Browse files Browse the repository at this point in the history
Fix unit test on windows: it looks like the replace-existing flag is
necessary to avoid AccessDeniedExceptions like this [example
failure](https://gradle-enterprise.elastic.co/s/4tjgx5vzblv36/tests/task/:server:test/details/org.elasticsearch.reservedstate.service.FileSettingsServiceTests/testProcessFileChanges?top-execution=1).

Resolves: elastic#115280
  • Loading branch information
n1v0lg authored and jfreden committed Nov 4, 2024
1 parent 9b92294 commit df06de1
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void testProcessFileChanges() throws Exception {
fileSettingsService.start();
fileSettingsService.clusterChanged(new ClusterChangedEvent("test", clusterService.state(), ClusterState.EMPTY_STATE));
// second file change; contents still don't matter
writeTestFile(fileSettingsService.watchedFile(), "{}");
overwriteTestFile(fileSettingsService.watchedFile(), "{}");

// wait for listener to be called (once for initial processing, once for subsequent update)
assertTrue(latch.await(20, TimeUnit.SECONDS));
Expand Down Expand Up @@ -355,6 +355,12 @@ public void testHandleSnapshotRestoreResetsMetadata() throws Exception {
private void writeTestFile(Path path, String contents) throws IOException {
Path tempFilePath = createTempFile();
Files.writeString(tempFilePath, contents);
Files.move(tempFilePath, path, StandardCopyOption.ATOMIC_MOVE);
Files.move(tempFilePath, path, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
}

private void overwriteTestFile(Path path, String contents) throws IOException {
Path tempFilePath = createTempFile();
Files.writeString(tempFilePath, contents);
Files.move(tempFilePath, path, StandardCopyOption.REPLACE_EXISTING);
}
}

0 comments on commit df06de1

Please sign in to comment.