Skip to content

Commit

Permalink
Fix Random Failing UIEditWorkingSetWizardAuto.testEditPage #275
Browse files Browse the repository at this point in the history
In my experiments, the test failed in roughly 2% of runs.

The test didn't close all processes which potentially
accessed the files it contained.
This PR Makes the Job-Manager join all jobs before finally deleting the
project-root.

#275
  • Loading branch information
Wittmaxi committed Apr 11, 2024
1 parent 781d89e commit 761cffd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
*******************************************************************************/
package org.eclipse.ui.tests.dialogs;

import java.util.List;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;

import java.util.List;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -57,8 +61,32 @@ private IWorkingSetPage getDefaultEditPage() {
return registry.getDefaultWorkingSetPage();
}

/**
* Blocks the calling thread until autobuild completes.
*/
public static void waitForBuild() {
((Workspace) getWorkspace()).getBuildManager().waitForAutoBuild();
}

/**
* Enables or disables workspace autobuild. Waits for the build to be finished,
* even if the autobuild value did not change and a previous build is still
* running.
*/
public static void setAutoBuilding(boolean enabled) throws CoreException {
IWorkspace workspace = getWorkspace();
if (workspace.isAutoBuilding() != enabled) {
IWorkspaceDescription description = workspace.getDescription();
description.setAutoBuilding(enabled);
workspace.setDescription(description);
}
waitForBuild();
}


@Test
public void testEditPage() throws Throwable {
setAutoBuilding(false);
IWizardPage page = getWizardDialog().getCurrentPage();
assertTrue(page instanceof IWorkingSetPage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
Expand Down Expand Up @@ -133,7 +133,7 @@ private void removeAllWorkingSets() {
}
}

private void cleanupWorkspace() {
private void cleanupWorkspace() throws OperationCanceledException {
try {
ResourcesPlugin.getWorkspace().getRoot().delete(true, null);
} catch (CoreException e) {
Expand Down

0 comments on commit 761cffd

Please sign in to comment.