Skip to content

Commit

Permalink
Disable the automatic snapshots for TestBug297635
Browse files Browse the repository at this point in the history
Disable the automatic snapshots while running tests in TestBug297635 to
avoid random failures.

Fixes #460
  • Loading branch information
fedejeanne committed Aug 4, 2023
1 parent 18d0171 commit 97869ab
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import org.eclipse.core.internal.utils.Messages;
import org.eclipse.core.internal.utils.Policy;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

/**
Expand All @@ -28,6 +31,7 @@ public class DelayedSnapshotJob extends Job {
private static final String MSG_SNAPSHOT = Messages.resources_snapshot;
private SaveManager saveManager;
private Workspace workspace;
private volatile boolean suspended;

public DelayedSnapshotJob(SaveManager manager, Workspace workspace) {
super(MSG_SNAPSHOT);
Expand All @@ -44,7 +48,7 @@ public DelayedSnapshotJob(SaveManager manager, Workspace workspace) {
public IStatus run(IProgressMonitor monitor) {
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
if (!workspace.isOpen()) {
if (!workspace.isOpen() || suspended) {
return Status.OK_STATUS;
}
try {
Expand All @@ -56,4 +60,29 @@ public IStatus run(IProgressMonitor monitor) {
saveManager.snapshotRequested = false;
}
}

/**
* Suspend automatic snapshots until {@link #resume()} is called.
*
* @see #resume()
*/
void suspend() {
suspended = true;
}

/**
* Resume automatic snapshots. This method does not schedule this Job.
*
* @see #suspend()
*/
void resume() {
suspended = false;
}

/**
* @return <code>true</code> if automatic snapshots are suspended.
*/
public boolean isSuspended() {
return suspended;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2205,4 +2205,16 @@ protected void writeWorkspaceFields(DataOutputStream output, IProgressMonitor mo
// save the registered sync partners in the synchronizer
((Synchronizer) workspace.getSynchronizer()).savePartners(output);
}

public void suspendSnapshotJob() {
snapshotJob.suspend();
}

public void resumeSnapshotJob() {
snapshotJob.resume();
}

public boolean isSnapshotJobSuspended() {
return snapshotJob.isSuspended();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,32 @@ public static Test suite() {
return new WorkspaceSessionTestSuite(AutomatedResourceTests.PI_RESOURCES_TESTS, TestBug297635.class);
}

private boolean snapshotsWereActive;

public BundleContext getContext() {
return Platform.getBundle(PI_RESOURCES_TESTS).getBundleContext();
}

@Override
protected void setUp() throws Exception {
super.setUp();
snapshotsWereActive = getSaveManager().isSnapshotJobSuspended();
getSaveManager().suspendSnapshotJob();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();

if (snapshotsWereActive) {
getSaveManager().resumeSnapshotJob();
}
}

private SaveManager getSaveManager() {
return ((Workspace) getWorkspace()).getSaveManager();
}

public void testBug() throws Exception {
installBundle();

Expand Down Expand Up @@ -136,11 +158,11 @@ private Map<String, SavedState> getSavedStatesFromSaveManager()
// there
Field field = SaveManager.class.getDeclaredField("savedStates");
field.setAccessible(true);
return (Map<String, SavedState>) field.get(((Workspace) getWorkspace()).getSaveManager());
return (Map<String, SavedState>) field.get(getSaveManager());
}

private void saveSnapshot() throws CoreException {
((Workspace) getWorkspace()).getSaveManager().save(ISaveContext.SNAPSHOT, true, null, getMonitor());
getSaveManager().save(ISaveContext.SNAPSHOT, true, null, getMonitor());
}

private void assertStateTrees(SavedState savedState, boolean isNull)
Expand Down

0 comments on commit 97869ab

Please sign in to comment.