Skip to content

Commit de75028

Browse files
authored
Make packaging test deletes robust for Windows (#135857)
Windows has crazy file locking behavior. This commit adjusts the rm utility method used by many tests to internally allow retries when on Windows, rather than explicitly needing to call rmWithRetries which can be missed. relates #113177
1 parent ede15bb commit de75028

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

qa/packaging/src/test/java/org/elasticsearch/packaging/util/Cleanup.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
import org.apache.logging.log4j.Logger;
1414

1515
import java.nio.file.Files;
16-
import java.nio.file.Path;
1716
import java.nio.file.Paths;
1817
import java.util.Arrays;
1918
import java.util.Collections;
2019
import java.util.List;
21-
import java.util.function.Consumer;
2220

2321
import static org.elasticsearch.packaging.test.PackagingTestCase.getRootTempDir;
2422
import static org.elasticsearch.packaging.util.FileUtils.lsGlob;
@@ -75,11 +73,9 @@ public static void cleanEverything() throws Exception {
7573
// when we run es as a role user on windows, add the equivalent here
7674
// delete files that may still exist
7775

78-
lsGlob(getRootTempDir(), "elasticsearch*").forEach(Platforms.WINDOWS ? FileUtils::rmWithRetries : FileUtils::rm);
76+
lsGlob(getRootTempDir(), "elasticsearch*").forEach(FileUtils::rm);
7977
final List<String> filesToDelete = Platforms.WINDOWS ? ELASTICSEARCH_FILES_WINDOWS : ELASTICSEARCH_FILES_LINUX;
80-
// windows needs leniency due to asinine releasing of file locking async from a process exiting
81-
Consumer<? super Path> rm = Platforms.WINDOWS ? FileUtils::rmWithRetries : FileUtils::rm;
82-
filesToDelete.stream().map(Paths::get).filter(Files::exists).forEach(rm);
78+
filesToDelete.stream().map(Paths::get).filter(Files::exists).forEach(FileUtils::rm);
8379
}
8480

8581
private static void purgePackagesLinux() {

qa/packaging/src/test/java/org/elasticsearch/packaging/util/FileUtils.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,21 @@ public static List<Path> lsGlob(Path directory, String glob) {
7575
}
7676

7777
public static void rm(Path... paths) {
78-
try {
79-
IOUtils.rm(paths);
80-
} catch (IOException e) {
81-
throw new RuntimeException(e);
78+
if (Platforms.WINDOWS) {
79+
rmWithRetries(paths);
80+
} else {
81+
try {
82+
IOUtils.rm(paths);
83+
} catch (IOException e) {
84+
throw new UncheckedIOException(e);
85+
}
8286
}
8387
}
8488

85-
public static void rmWithRetries(Path... paths) {
89+
// windows needs leniency due to asinine releasing of file locking async from a process exiting
90+
private static void rmWithRetries(Path... paths) {
8691
int tries = 10;
87-
Exception exception = null;
92+
IOException exception = null;
8893
while (tries-- > 0) {
8994
try {
9095
IOUtils.rm(paths);
@@ -103,7 +108,7 @@ public static void rmWithRetries(Path... paths) {
103108
return;
104109
}
105110
}
106-
throw new RuntimeException(exception);
111+
throw new UncheckedIOException(exception);
107112
}
108113

109114
public static Path mktempDir(Path path) {

0 commit comments

Comments
 (0)