Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-10-13 06:02:33 +0000
committerThomas Wolf2019-11-27 09:22:23 +0000
commitc609d6d4e309baf590feeed2d30db4e21eb05e40 (patch)
tree813116a0f844d066a7a8e93ac1ba99930bcc98fb
parentbeeaff3c6ab98bc1685d5657b4ae3dec26c7f6c2 (diff)
downloadegit-c609d6d4e309baf590feeed2d30db4e21eb05e40.tar.gz
egit-c609d6d4e309baf590feeed2d30db4e21eb05e40.tar.xz
egit-c609d6d4e309baf590feeed2d30db4e21eb05e40.zip
[releng] Try project deletion multiple times
We sometimes see test failures in the master build caused by not being able to delete a test project. See builds 173, 170, 165... for examples. Therefore repeat project deletion in case of error, as it may be locked by some other concurrent processing. Change-Id: I3dbeba99a4d5bf5a6e0c9e960c5abb2277c057a1 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
-rw-r--r--org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestProject.java11
-rw-r--r--org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestUtils.java47
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java40
3 files changed, 55 insertions, 43 deletions
diff --git a/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestProject.java b/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestProject.java
index acef0d0408..c27eb0fc64 100644
--- a/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestProject.java
+++ b/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestProject.java
@@ -92,8 +92,9 @@ public class TestProject {
IProjectDescription description = createDescription(path, insidews,
root);
project = root.getProject(description.getName());
- if (remove)
- project.delete(true, null);
+ if (remove) {
+ TestUtils.deleteProject(project);
+ }
IPath locationBefore = null;
URI locationURI = description.getLocationURI();
if (locationURI != null) {
@@ -204,9 +205,9 @@ public class TestProject {
public void dispose() throws CoreException, IOException {
waitForIndexer();
- if (project.exists())
- project.delete(true, true, null);
- else {
+ if (project.exists()) {
+ TestUtils.deleteProject(project);
+ } else {
File f = new File(location);
if (f.exists())
FileUtils.delete(f, FileUtils.RECURSIVE | FileUtils.RETRY);
diff --git a/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestUtils.java b/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestUtils.java
index a18cd8935b..207269e618 100644
--- a/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestUtils.java
+++ b/org.eclipse.egit.core.junit/src/org/eclipse/egit/core/test/TestUtils.java
@@ -35,8 +35,10 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.IJobManager;
@@ -55,6 +57,10 @@ public class TestUtils {
private final static File rootDir = customTestDirectory();
+ private static final int MAX_DELETE_RETRY = 5;
+
+ private static final int DELETE_RETRY_DELAY = 1000; // ms
+
/**
* Allow to set a custom directory for running tests
*
@@ -412,4 +418,45 @@ public class TestUtils {
return dump.toString();
}
+ /**
+ * Delete a project and repeat multiple times in case of resource deletion
+ * errors. A {@link ICoreRunnable} is used to avoid concurrent activities
+ * disturbing the deletion.
+ *
+ * @param project
+ *
+ * @throws CoreException
+ */
+ public static void deleteProject(IProject project) throws CoreException {
+ ResourcesPlugin.getWorkspace().run(monitor -> {
+ // Following code inspired by {@link
+ // org.eclipse.jdt.testplugin.JavaProjectHelper#delete(IResource)}.
+ // Sometimes resource deletion may fail due to concurrently held
+ // locks.
+ for (int i = 0; i < MAX_DELETE_RETRY; i++) {
+ try {
+ project.delete(
+ IResource.FORCE
+ | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
+ null);
+ break;
+ } catch (CoreException e) {
+ if (i == MAX_DELETE_RETRY - 1) {
+ throw e;
+ }
+ try {
+ org.eclipse.egit.core.Activator.logInfo(
+ "Sleep before retrying to delete project "
+ + project.getLocationURI());
+ // Give other threads the time to close and release
+ // the resource.
+ Thread.sleep(DELETE_RETRY_DELAY);
+ } catch (InterruptedException e1) {
+ // Ignore and retry to delete
+ }
+ }
+ }
+ }, null);
+ }
+
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java
index eb602c628a..4013f75da3 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java
@@ -32,6 +32,7 @@ import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.core.test.TestUtils;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
@@ -61,10 +62,6 @@ public class JavaProjectTester {
public static final String INITIAL_FILE_CONTENT = "package " + PACKAGE_NAME
+ ";\nclass " + JAVA_CLASS_NAME + " {\n\n}";
- private static final int MAX_DELETE_RETRY = 5;
-
- private static final int DELETE_RETRY_DELAY = 1000; // ms
-
private final LocalRepositoryTestCase testCase;
public JavaProjectTester(LocalRepositoryTestCase testCase) {
@@ -190,40 +187,7 @@ public class JavaProjectTester {
return;
}
final IProject project = javaProject.getProject();
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- // Following code inspired by {@link
- // org.eclipse.jdt.testplugin.JavaProjectHelper#delete(IResource)}.
- // I don't like all this sleeping at all, but apparently it's
- // needed because the Java indexer might still run and hold on
- // to some resources.
- for (int i = 0; i < MAX_DELETE_RETRY; i++) {
- try {
- project.delete(IResource.FORCE
- | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
- null);
- break;
- } catch (CoreException e) {
- if (i == MAX_DELETE_RETRY - 1) {
- throw e;
- }
- try {
- Activator.logInfo(
- "Sleep before retrying to delete project "
- + project.getLocationURI());
- // Give other threads the time to close and release
- // the resource.
- Thread.sleep(DELETE_RETRY_DELAY);
- } catch (InterruptedException e1) {
- // Ignore and retry to delete
- }
- }
- }
-
- }
- };
- ResourcesPlugin.getWorkspace().run(runnable, null);
+ TestUtils.deleteProject(project);
}
}

Back to the top