Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-02-21 11:44:46 +0000
committerMatthias Sohn2016-02-21 15:43:01 +0000
commitfb572c34715624163d1ee5e74cd87b020bf3d295 (patch)
treef108189801ec7d04393907a9d664a1dd9ffebbb1 /org.eclipse.egit.ui.test
parentaf5c88dc1ce31f1d8ee5890b75242f40b4d87a3d (diff)
downloadegit-fb572c34715624163d1ee5e74cd87b020bf3d295.tar.gz
egit-fb572c34715624163d1ee5e74cd87b020bf3d295.tar.xz
egit-fb572c34715624163d1ee5e74cd87b020bf3d295.zip
Test stability: GitRepositoriesView tests
Test failure in [1] claimed that no refresh job was scheduled. The RepositoriesView schedules a refresh on its own in response to an index diff change. If a refresh job is already scheduled and not running yet, the re-schedule in view.refresh() has no effect. See JobManager.schedule(). As a result, the JobListener is never notified about a scheduled job. Moreover, if the job is already running, re-scheduling will make it run again, but the JobListener will return already when the currently running job finishes. Therefore, we just need to wait for refresh jobs after having called view.refresh(). That will make the test wait in any case. Timeout can be implemented via a custom progress monitor. [1] https://hudson.eclipse.org/egit/job/egit.gerrit/8154/testReport/junit/org.eclipse.egit.ui.view.repositories/GitRepositoriesViewBranchHandlingTest/testCheckoutRemote/ Change-Id: I2ecd20b4caaf70e00a903366f46da0075afa6a3f Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java33
1 files changed, 30 insertions, 3 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
index 0319024622..fa196db566 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
@@ -12,6 +12,7 @@ package org.eclipse.egit.ui.view.repositories;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -20,6 +21,9 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.core.commands.State;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.RepositoryUtil;
@@ -29,7 +33,6 @@ import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.tree.command.ToggleBranchCommitCommand;
-import org.eclipse.egit.ui.test.JobJoiner;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -115,9 +118,13 @@ public abstract class GitRepositoriesViewTestBase extends
protected void refreshAndWait() throws Exception {
RepositoriesView view = (RepositoriesView) getOrOpenView()
.getReference().getPart(true);
- JobJoiner jobJoiner = JobJoiner.startListening(JobFamilies.REPO_VIEW_REFRESH, 60, TimeUnit.SECONDS);
view.refresh();
- jobJoiner.join();
+ try {
+ Job.getJobManager().join(JobFamilies.REPO_VIEW_REFRESH,
+ new TimeoutProgressMonitor(60, TimeUnit.SECONDS));
+ } catch (OperationCanceledException e) {
+ fail("Refresh took longer 60 seconds");
+ }
TestUtil.processUIEvents();
}
@@ -129,4 +136,24 @@ public abstract class GitRepositoriesViewTestBase extends
assertEquals("Project existence " + projectName, prj.exists(),
existence);
}
+
+ private static class TimeoutProgressMonitor extends NullProgressMonitor {
+
+ private final long stopTime;
+
+ public TimeoutProgressMonitor(long timeUnits, TimeUnit timeUnit) {
+ stopTime = System.currentTimeMillis()
+ + timeUnit.toMillis(timeUnits);
+ }
+
+ @Override
+ public boolean isCanceled() {
+ boolean canceled = super.isCanceled();
+ if (canceled) {
+ return true;
+ }
+ setCanceled(System.currentTimeMillis() > stopTime);
+ return super.isCanceled();
+ }
+ }
}

Back to the top