From 80fdafd124635b9f6e92e239fd2d2546406e3d60 Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Mon, 13 Feb 2023 17:02:18 +0100 Subject: [PATCH] Try to reduce flakiness on Windows for BwoB tests --- .../lib/remote/util/IntegrationTestUtils.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/google/devtools/build/lib/remote/util/IntegrationTestUtils.java b/src/test/java/com/google/devtools/build/lib/remote/util/IntegrationTestUtils.java index 44e204f06b53f7..6f57428ef82476 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/util/IntegrationTestUtils.java +++ b/src/test/java/com/google/devtools/build/lib/remote/util/IntegrationTestUtils.java @@ -27,6 +27,10 @@ import java.net.DatagramSocket; import java.net.ServerSocket; import java.net.SocketException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; import java.util.Random; /** Integration test utilities. */ @@ -140,8 +144,17 @@ private WorkerInstance( this.pidPath = pidPath; } - public void stop() { + public void stop() throws IOException { process.destroyAndWait(); + deleteDir(workPath); + deleteDir(casPath); + new File(pidPath.getSafePathString()).delete(); + } + + private static void deleteDir(PathFragment path) throws IOException { + try (var stream = Files.walk(Paths.get(path.getSafePathString()))) { + stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + } } public int getPort() {