Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorStefan Xenos2016-10-21 20:52:06 +0000
committerStefan Xenos2016-11-01 13:47:40 +0000
commit869d1af247764d332a92d961fd216b0c209e42f3 (patch)
treed32ee1ca382025021a8d5db3438c530836aa2103 /tests
parentafb6ad45df560cdd919832c98505ba634949e925 (diff)
downloadeclipse.platform.team-869d1af247764d332a92d961fd216b0c209e42f3.tar.gz
eclipse.platform.team-869d1af247764d332a92d961fd216b0c209e42f3.tar.xz
eclipse.platform.team-869d1af247764d332a92d961fd216b0c209e42f3.zip
Bug 506368 - CVS test failures in N20161020
Ensure that there are no outstanding Jobs or *syncExecs still pending between tests. Change-Id: I4374f34520fbaf3dc1abe34922c65c5deecaf7b1 Signed-off-by: Stefan Xenos <sxenos@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java3
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestUtil.java87
2 files changed, 89 insertions, 1 deletions
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
index 9d7c8ad2d..d9d0fb8ce 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -1164,6 +1164,7 @@ public class EclipseTest extends ResourceTest {
}
}
}
+ TestUtil.cleanUp();
}
private void obtainCVSServerLock() {
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestUtil.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestUtil.java
new file mode 100644
index 000000000..e7e915b9a
--- /dev/null
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestUtil.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Xenos (Google) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.team.tests.ccvs.core;
+
+import org.junit.Assert;
+
+import org.eclipse.swt.widgets.Display;
+
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.core.runtime.jobs.Job;
+
+public class TestUtil {
+ /**
+ * Call this in the tearDown method of every test to clean up state that can
+ * otherwise leak through SWT between tests.
+ */
+ public static void cleanUp() {
+ // Ensure that the Thread.interrupted() flag didn't leak.
+ Assert.assertFalse("The main thread should not be interrupted at the end of a test", Thread.interrupted());
+ // Wait for any outstanding jobs to finish. Protect against deadlock by
+ // terminating the wait after a timeout.
+ boolean timedOut = waitForJobs(0, TimeUnit.MINUTES.toMillis(3));
+ Assert.assertFalse("Some Job did not terminate at the end of the test", timedOut);
+ // Wait for any pending *syncExec calls to finish
+ runEventLoop();
+ // Ensure that the Thread.interrupted() flag didn't leak.
+ Assert.assertFalse("The main thread should not be interrupted at the end of a test", Thread.interrupted());
+ }
+
+ public static void runEventLoop() {
+ Display display = Display.getCurrent();
+ if (display != null && !display.isDisposed()) {
+ while (display.readAndDispatch()) {
+ // Keep pumping events until the queue is empty
+ }
+ }
+ }
+
+ /**
+ * Utility for waiting until the execution of jobs of any family has
+ * finished or timeout is reached. If no jobs are running, the method waits
+ * given minimum wait time. While this method is waiting for jobs, UI events
+ * are processed.
+ *
+ * @param minTimeMs
+ * minimum wait time in milliseconds
+ * @param maxTimeMs
+ * maximum wait time in milliseconds
+ * @return true if the method timed out, false if all the jobs terminated
+ * before the timeout
+ */
+ public static boolean waitForJobs(long minTimeMs, long maxTimeMs) {
+ if (maxTimeMs < minTimeMs) {
+ throw new IllegalArgumentException("Max time is smaller as min time!");
+ }
+ final long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() - start < minTimeMs) {
+ runEventLoop();
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // Uninterruptable
+ }
+ }
+ while (!Job.getJobManager().isIdle()) {
+ if (System.currentTimeMillis() - start >= maxTimeMs) {
+ return true;
+ }
+ runEventLoop();
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // Uninterruptable
+ }
+ }
+ return false;
+ }
+}

Back to the top