Skip to content

Commit

Permalink
use TestBarrier2 (eclipse-platform#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jukzi authored Apr 19, 2022
1 parent 7c144e6 commit 6dc15f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.core.runtime.jobs.ILock;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.tests.harness.TestBarrier;
import org.eclipse.core.tests.harness.TestBarrier2;
import org.eclipse.swt.widgets.Display;
import org.junit.Test;

Expand Down Expand Up @@ -71,34 +71,34 @@ public boolean contains(ISchedulingRule rule) {
@Test
public void testBug262032() {
final ILock lock = Job.getJobManager().newLock();
final TestBarrier tb1 = new TestBarrier(-1);
final TestBarrier2 tb1 = new TestBarrier2(-1);

// Job hols scheduling rule
Job j = new Job ("Deadlocking normal Job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
tb1.setStatus(TestBarrier.STATUS_WAIT_FOR_START);
tb1.waitForStatus(TestBarrier.STATUS_RUNNING);
tb1.setStatus(TestBarrier2.STATUS_WAIT_FOR_START);
tb1.waitForStatus(TestBarrier2.STATUS_RUNNING);
lock.acquire();
//test that we haven't both acquired the lock...
assertTrue(!concurrentAccess);
lock.release();

tb1.setStatus(TestBarrier.STATUS_WAIT_FOR_DONE);
tb1.setStatus(TestBarrier2.STATUS_WAIT_FOR_DONE);
return Status.OK_STATUS;
}
};
j.setRule(identityRule);
j.schedule();

// Wait for the job with scheduling rule to start
tb1.waitForStatus(TestBarrier.STATUS_WAIT_FOR_START);
tb1.waitForStatus(TestBarrier2.STATUS_WAIT_FOR_START);

// asyncExec job that wants the lock
Display.getDefault().asyncExec(() -> {
lock.acquire();
concurrentAccess = true;
tb1.setStatus(TestBarrier.STATUS_RUNNING);
tb1.setStatus(TestBarrier2.STATUS_RUNNING);
// Sleep to test for concurrent access
try {
Thread.sleep(1000);
Expand All @@ -114,7 +114,7 @@ protected IStatus run(IProgressMonitor monitor) {

try {
j.join();
tb1.waitForStatus(TestBarrier.STATUS_WAIT_FOR_DONE);
tb1.waitForStatus(TestBarrier2.STATUS_WAIT_FOR_DONE);
assertEquals(Status.OK_STATUS, j.getResult());
} catch (InterruptedException e) {fail();}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import static org.junit.Assert.assertTrue;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicIntegerArray;

import org.eclipse.core.resources.ResourcesPlugin;
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;
import org.eclipse.core.tests.harness.TestBarrier;
import org.eclipse.core.tests.harness.TestBarrier2;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -65,11 +66,11 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
}
};
job.setRule(ResourcesPlugin.getWorkspace().getRoot());
final int[] status = new int[] { -1 };
final AtomicIntegerArray status = new AtomicIntegerArray(new int[] { -1 });
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) {
status[0] = TestBarrier.STATUS_DONE;
status.set(0, TestBarrier2.STATUS_DONE);
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(
Expand All @@ -78,7 +79,7 @@ protected void execute(IProgressMonitor monitor) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
TestBarrier.waitForStatus(status, TestBarrier.STATUS_DONE);
TestBarrier2.waitForStatus(status, TestBarrier2.STATUS_DONE);
return Status.OK_STATUS;
} catch (AssertionFailedError e) {
// syncExecs are processed by
Expand Down

0 comments on commit 6dc15f1

Please sign in to comment.