Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-06-29 19:42:41 +0000
committerAndrey Loskutov2015-06-29 21:34:48 +0000
commit3cf4821a5e2068d964a5e18bc19848a16f431896 (patch)
tree5caef39c69c16fec67733211cc88ff1201d8b842 /org.eclipse.egit.ui.test
parent686faa31fdb50efbcef4112af66d033d793d4420 (diff)
downloadegit-3cf4821a5e2068d964a5e18bc19848a16f431896.tar.gz
egit-3cf4821a5e2068d964a5e18bc19848a16f431896.tar.xz
egit-3cf4821a5e2068d964a5e18bc19848a16f431896.zip
Test stability fixes related to job scheduling/resource changes etc
Trying to fix instabilities in recently failed unstable tests: Job.join() can immediately return if expected job is not yet scheduled. So let TestUtil.joinJobs() wait before joining. Many git operations may trigger resource changes, resource changes can trigger jobs via listeners, so make sure we proceed eventually triggered jobs after such events. Change-Id: If8017ab14dca8e1d5422ae2b024195601d334e31 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.java30
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java59
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java2
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java1
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java1
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java8
6 files changed, 75 insertions, 26 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 9f9b690304..090b879702 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
@@ -207,16 +207,17 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
protected static void deleteAllProjects() throws Exception {
for (IProject prj : ResourcesPlugin.getWorkspace().getRoot()
- .getProjects())
- if (prj.getName().equals(PROJ1))
+ .getProjects()) {
+ if (prj.getName().equals(PROJ1)) {
prj.delete(false, false, null);
- else if (prj.getName().equals(PROJ2)) {
+ } else if (prj.getName().equals(PROJ2)) {
// delete the .project on disk
File dotProject = prj.getLocation().append(".project").toFile();
prj.delete(false, false, null);
FileUtils.delete(dotProject, FileUtils.RETRY);
}
-
+ }
+ TestUtil.waitForJobs(50, 5000);
}
protected File createProjectAndCommitToRepository() throws Exception {
@@ -238,7 +239,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
if (firstProject.exists()) {
firstProject.delete(true, null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
}
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(PROJ1);
@@ -246,7 +247,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
.getPath()));
firstProject.create(desc, null);
firstProject.open(null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
IFolder folder = firstProject.getFolder(FOLDER);
folder.create(false, true, null);
@@ -264,7 +265,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
if (secondProject.exists()) {
secondProject.delete(true, null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
}
desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2);
@@ -282,7 +283,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
secondtextFile2.create(new ByteArrayInputStream("Some more content"
.getBytes(firstProject.getDefaultCharset())), false, null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
// TODO we should be able to hide the .project
// IFile gitignore = secondPoject.getFile(".gitignore");
@@ -290,6 +291,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
// .getBytes(firstProject.getDefaultCharset())), false, null);
new ConnectProviderOperation(secondProject, gitDir).execute(null);
+ TestUtil.waitForJobs(50, 1000);
IFile[] commitables = new IFile[] { firstProject.getFile(".project"),
textFile, textFile2, secondtextFile, secondtextFile2 };
@@ -404,6 +406,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
updateRef
.setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$
updateRef.update();
+ TestUtil.waitForJobs(50, 5000);
}
protected void assertClickOpens(SWTBotTree tree, String menu, String window) {
@@ -421,7 +424,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
* @throws InterruptedException
*/
protected static void waitInUI() throws InterruptedException {
- Thread.sleep(1000);
+ TestUtil.processUIEvents(1000);
}
protected void shareProjects(File repositoryDir) throws Exception {
@@ -431,8 +434,8 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
return name.equals(".project");
}
};
- for (File file : myRepository.getWorkTree().listFiles())
- if (file.isDirectory())
+ for (File file : myRepository.getWorkTree().listFiles()) {
+ if (file.isDirectory()) {
if (file.list(projectFilter).length > 0) {
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(file.getName());
@@ -445,6 +448,9 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
new ConnectProviderOperation(prj, myRepository
.getDirectory()).execute(null);
}
+ }
+ }
+ TestUtil.waitForJobs(50, 5000);
}
@SuppressWarnings("boxing")
@@ -496,6 +502,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER,
message);
op.execute(null);
+ TestUtil.waitForJobs(50, 5000);
}
/**
@@ -558,6 +565,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER,
commitMessage);
op.execute(null);
+ TestUtil.waitForJobs(50, 5000);
}
protected static void setTestFileContent(String newContent)
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 a684388e7b..d31ba4db8a 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
@@ -37,6 +37,7 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.commit.CommitHelper;
import org.eclipse.egit.ui.internal.commit.CommitHelper.CommitInfo;
+import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -60,6 +61,7 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
+import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
@@ -163,7 +165,11 @@ public class TestUtil {
* @throws InterruptedException
*/
public static void joinJobs(Object family) throws InterruptedException {
+ // join() returns immediately if the job is not yet scheduled.
+ // To avoid unstable tests, let us first wait some time
+ TestUtil.waitForJobs(50, 1000);
Job.getJobManager().join(family, null);
+ TestUtil.processUIEvents();
}
/**
@@ -197,9 +203,35 @@ public class TestUtil {
* until all pending events are processed in UI thread.
*/
public static void processUIEvents() {
+ processUIEvents(0);
+ }
+
+ /**
+ * Process all queued UI events. If called from background thread, blocks
+ * until all pending events are processed in UI thread.
+ *
+ * @param timeInMillis
+ * time to wait. During this time all UI events are processed but
+ * the current thread is blocked
+ */
+ public static void processUIEvents(final long timeInMillis) {
if (Display.getCurrent() != null) {
- while (Display.getCurrent().readAndDispatch()) {
- // process queued ui events
+ if (timeInMillis <= 0) {
+ while (Display.getCurrent().readAndDispatch()) {
+ // process queued ui events at least once
+ }
+ } else {
+ long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() - start <= timeInMillis) {
+ while (Display.getCurrent().readAndDispatch()) {
+ // process queued ui events
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ }
}
} else {
// synchronously refresh UI
@@ -639,26 +671,29 @@ public class TestUtil {
public static void hideView(final String viewId) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
- IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
- IViewReference[] views = workbenchPage.getViewReferences();
- for (int i = 0; i < views.length; i++) {
- IViewReference view = views[i];
- if (viewId.equals(view.getId())) {
- workbenchPage.hideView(view);
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
+ .getWorkbenchWindows();
+ for (IWorkbenchWindow window : windows) {
+ IWorkbenchPage workbenchPage = window.getActivePage();
+ IViewReference[] views = workbenchPage.getViewReferences();
+ for (int i = 0; i < views.length; i++) {
+ IViewReference view = views[i];
+ if (viewId.equals(view.getId())) {
+ workbenchPage.hideView(view);
+ }
}
+ processUIEvents();
}
}
});
}
public static SWTBotView showHistoryView() {
- return showView("org.eclipse.team.ui.GenericHistoryView");
+ return showView(IHistoryView.VIEW_ID);
}
public static SWTBotView showExplorerView() {
- return showView("org.eclipse.jdt.ui.PackageExplorer");
+ return showView(JavaUI.ID_PACKAGES);
}
public static SWTBotTree getExplorerTree() {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java
index 6e474c168e..85c921494e 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java
@@ -23,6 +23,7 @@ import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.push.PushOperationUI;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.JobJoiner;
+import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
@@ -108,6 +109,7 @@ public class GitRepositoriesViewFetchAndPushTest extends
new Git(repository).branchRename().setOldName(currentBranch)
.setNewName("" + System.currentTimeMillis()).call();
+ TestUtil.waitForJobs(50, 5000);
selectNode(tree, useRemote, false);
runPush(tree);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java
index 63fe7e825a..25e0c7d80c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java
@@ -166,6 +166,7 @@ public class GitRepositoriesViewTagHandlingTest extends
bot.shell(UIText.ResetTargetSelectionDialog_ResetQuestion).bot()
.button(IDialogConstants.YES_LABEL).click();
+ TestUtil.waitForJobs(50, 5000);
Job.getJobManager().join(JobFamilies.RESET, null);
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
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 d5590c40cb..5cebb888dc 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
@@ -119,6 +119,7 @@ public abstract class GitRepositoriesViewTestBase extends
JobJoiner jobJoiner = JobJoiner.startListening(JobFamilies.REPO_VIEW_REFRESH, 60, TimeUnit.SECONDS);
view.refresh();
jobJoiner.join();
+ TestUtil.processUIEvents();
}
@SuppressWarnings("boxing")
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java
index 94b738f8fe..e047270b18 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java
@@ -95,7 +95,7 @@ public abstract class AbstractSynchronizeViewTest extends
.getProject(EMPTY_PROJECT);
if (prj.exists()) {
prj.delete(false, false, null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
}
}
@@ -199,7 +199,7 @@ public abstract class AbstractSynchronizeViewTest extends
if (firstProject.exists()) {
firstProject.delete(true, null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
}
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(EMPTY_PROJECT);
@@ -216,9 +216,11 @@ public abstract class AbstractSynchronizeViewTest extends
IFile textFile2 = folder.getFile(FILE2);
textFile2.create(new ByteArrayInputStream("Some more content"
.getBytes(firstProject.getDefaultCharset())), false, null);
- TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForJobs(50, 5000);
new ConnectProviderOperation(firstProject, gitDir).execute(null);
+
+ TestUtil.waitForJobs(50, 5000);
}
protected SWTBotTreeItem waitForNodeWithText(SWTBotTree tree, String name) {

Back to the top