diff options
author | Alexander Kriegisch | 2021-05-17 00:29:53 +0000 |
---|---|---|
committer | Manoj Palat | 2021-06-30 10:14:34 +0000 |
commit | 979b789957a22b516663198d9b3ca1a37caae3fc (patch) | |
tree | 8907725e008f12a1aa59529ffc866aae87a08355 /org.eclipse.jdt.core.tests.compiler | |
parent | d69da10b2caf334f6c212a97365cc16a8da83253 (diff) | |
download | eclipse.jdt.core-979b789957a22b516663198d9b3ca1a37caae3fc.tar.gz eclipse.jdt.core-979b789957a22b516663198d9b3ca1a37caae3fc.tar.xz eclipse.jdt.core-979b789957a22b516663198d9b3ca1a37caae3fc.zip |
Bug 573363: Add option to skip retrying deletion in Util
New flag Util.SKIP_RETRY_DELETE_FILE can optionally be used in order to
skip time-consuming file deletion retries in favour of registering
non-deletable files for deletion via File.deleteOnExit(). This option is
off by default and not used by any test (yet), but feel free to use it
both locally during development and in CI builds, because especially on
Windows it is quite likely that any non-deletable file is locked and
still going to be non-deletable after waiting for DELETE_MAX_WAIT ms.
Given the fact that JVMs are often re-used for multiple test runs,
deletion retry times can multiply because the same locked file from the
previous test run is tried to be deleted again.
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Change-Id: I706bdbab29e080d0aa9f2f7fb20822c658be92fd
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/180716
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Reviewed-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
Reviewed-by: Manoj Palat <manpalat@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler')
-rw-r--r-- | org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java index b8b092f68f..badd925b0e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java @@ -67,8 +67,20 @@ public class Util { * To avoid too many loops while waiting, the ten first ones are done waiting * 10ms before repeating, the ten loops after are done waiting 100ms and * the other loops are done waiting 1s... + * <br> + * If you wish to avoid retrying file deletion during tests altogether, activate + * {@link #SKIP_RETRY_DELETE_FILE}. */ public static int DELETE_MAX_WAIT = 10000; + /** + * If you wish to avoid retrying file deletion during tests altogether, set the value to true. + * Then each undeleted file will be registered for deletion during JVM shutdown via + * {@link File#deleteOnExit()} instead of waiting for {@link #DELETE_MAX_WAIT} ms. + * <br> + * Please note: This flag only influences the behaviour of {@link #delete(File)} and + * {@link #delete(String)}. It is being ignored by {@link #delete(IResource)}. + */ + public static boolean SKIP_RETRY_DELETE_FILE = false; private static final boolean DEBUG = false; /** @@ -511,8 +523,17 @@ public static boolean delete(File file) { // remove file or empty directory if (file.delete()) { return true; + } else { + if (SKIP_RETRY_DELETE_FILE) { + System.out.println(); + System.out.println("WARNING in test: "+getTestName()); + System.out.println(" - cannot delete " + file + " -> registering for deletion on JVM exit"); + file.deleteOnExit(); + return false; + } else { + return waitUntilFileDeleted(file); + } } - return waitUntilFileDeleted(file); } /** * Delete a file or directory and insure that the file is no longer present |