Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-06-28 18:25:55 +0000
committerAndrey Loskutov2015-06-28 18:25:55 +0000
commit4830faad99e65a6b5a495d5da6b560645658a88c (patch)
treee4c61ad32c213295a809719a274e83135eae3fce /org.eclipse.egit.ui.test
parentd537234a7bf30e7f1f4fbe643080354b5cc02162 (diff)
downloadegit-4830faad99e65a6b5a495d5da6b560645658a88c.tar.gz
egit-4830faad99e65a6b5a495d5da6b560645658a88c.tar.xz
egit-4830faad99e65a6b5a495d5da6b560645658a88c.zip
Introduced waitForJobs() after resetWorkspace and project operations
To be more stable, unit tests should wait for jobs which might be triggered after resource operations. Change-Id: Iab28f65bc163b82a8f3573611d329eedc0412580 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java11
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java26
2 files changed, 35 insertions, 2 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
index a42c1f9882..b5131a36f2 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
@@ -171,6 +171,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
.getProjects())
project.delete(false, false, null);
shutDownRepositories();
+ TestUtil.waitForJobs(50, 5000);
}
@BeforeClass
@@ -235,14 +236,17 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
IProject firstProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(PROJ1);
- if (firstProject.exists())
+ if (firstProject.exists()) {
firstProject.delete(true, null);
+ TestUtil.waitForJobs(100, 5000);
+ }
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(PROJ1);
desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ1)
.getPath()));
firstProject.create(desc, null);
firstProject.open(null);
+ TestUtil.waitForJobs(100, 5000);
IFolder folder = firstProject.getFolder(FOLDER);
folder.create(false, true, null);
@@ -258,14 +262,17 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
IProject secondProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(PROJ2);
- if (secondProject.exists())
+ if (secondProject.exists()) {
secondProject.delete(true, null);
+ TestUtil.waitForJobs(100, 5000);
+ }
desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2);
desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ2)
.getPath()));
secondProject.create(desc, null);
secondProject.open(null);
+ TestUtil.waitForJobs(100, 5000);
IFolder secondfolder = secondProject.getFolder(FOLDER);
secondfolder.create(false, true, null);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
index 1bf1e586df..a684388e7b 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
@@ -167,6 +167,32 @@ public class TestUtil {
}
/**
+ * 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
+ */
+ public static void 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) {
+ processUIEvents();
+ }
+ while (!Job.getJobManager().isIdle()
+ && System.currentTimeMillis() - start < maxTimeMs) {
+ processUIEvents();
+ }
+ }
+
+ /**
* Process all queued UI events. If called from background thread, blocks
* until all pending events are processed in UI thread.
*/

Back to the top