Skip to content

Commit 5d71e17

Browse files
basilevsiloveeclipse
authored andcommitted
Ensure the background payload starts #2323
If background job with concurrent access payload does not have a chance to start, the test harness kills it prematurely. This change avoids a dependency on a job startup timing. Fixes #2323
1 parent 9fb4063 commit 5d71e17

File tree

1 file changed

+10
-3
lines changed
  • resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression

1 file changed

+10
-3
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.io.OutputStream;
31+
import java.util.concurrent.BrokenBarrierException;
32+
import java.util.concurrent.CyclicBarrier;
3133
import org.eclipse.core.resources.IFile;
3234
import org.eclipse.core.resources.IFolder;
3335
import org.eclipse.core.resources.IProject;
@@ -136,11 +138,13 @@ public void testBug43936() throws CoreException {
136138
* Do not throw RuntimeException when accessing a deleted file
137139
*/
138140
@Test
139-
public void testIssue2290() throws CoreException, InterruptedException {
141+
public void testIssue2290() throws CoreException, InterruptedException, BrokenBarrierException {
140142
IProject project = getWorkspace().getRoot().getProject("MyProject");
141143
IFile subject = project.getFile("subject.txt");
144+
CyclicBarrier jobStart = new CyclicBarrier(2);
142145
Job createDelete = Job.create("Create/delete", monitor -> {
143146
try {
147+
jobStart.await();
144148
while (!monitor.isCanceled()) {
145149
createInWorkspace(subject);
146150
while (!monitor.isCanceled()) {
@@ -157,14 +161,17 @@ public void testIssue2290() throws CoreException, InterruptedException {
157161
}
158162
} catch (CoreException e) {
159163
return e.getStatus();
164+
} catch (BrokenBarrierException | InterruptedException e1) {
165+
return Status.error("Job has failed to start", e1);
160166
}
161167
return Status.OK_STATUS;
162168
});
163169
createDelete.setPriority(Job.INTERACTIVE);
164170

165-
long stop = currentTimeMillis() + 1000;
166171
try {
167172
createDelete.schedule();
173+
jobStart.await();
174+
long stop = currentTimeMillis() + 1000;
168175
while (currentTimeMillis() < stop) {
169176
assertContentAccessibleOrNotFound(subject); // should not throw
170177
}
@@ -173,7 +180,7 @@ public void testIssue2290() throws CoreException, InterruptedException {
173180
createDelete.join();
174181
IStatus result = createDelete.getResult();
175182
if (!result.isOK()) {
176-
throw new CoreException(result);
183+
throw new AssertionError(result.toString(), new CoreException(result));
177184
}
178185
}
179186
}

0 commit comments

Comments
 (0)