From fd911d09696184593382b28597db0d9fb9d68f80 Mon Sep 17 00:00:00 2001 From: Chris Frohoff Date: Fri, 16 Nov 2018 11:02:44 -0800 Subject: [PATCH] fix (hopefully) test flakiness --- .../ysoserial/payloads/FileUploadTest.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/test/java/ysoserial/payloads/FileUploadTest.java b/src/test/java/ysoserial/payloads/FileUploadTest.java index 01c31b6..ee186ec 100644 --- a/src/test/java/ysoserial/payloads/FileUploadTest.java +++ b/src/test/java/ysoserial/payloads/FileUploadTest.java @@ -47,9 +47,12 @@ public class FileUploadTest implements CustomTest { payload.call(); File found = null; - for ( File f : this.repo.listFiles()) { - found = f; - break; + for (int i = 0; i < 50 && found == null; i++) { // try for 5s before failing + for (File f : this.repo.listFiles()) { + found = f; + break; + } + Thread.sleep(100); } Assert.assertNotNull("File not copied", found); if (OS.get() != OS.WINDOWS) { @@ -60,11 +63,21 @@ public class FileUploadTest implements CustomTest { } finally { if ( this.repo.exists()) { for ( File f : this.repo.listFiles()) { - f.deleteOnExit(); + safeDeleteOnExit(f); } - this.repo.deleteOnExit(); + safeDeleteOnExit(this.repo); } - this.source.deleteOnExit(); + safeDeleteOnExit(this.source); + } + } + + private static void safeDeleteOnExit(File f) { + try { + if (f.exists()) { + f.deleteOnExit(); + } + } catch (Exception e) { + e.printStackTrace(); } }