-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FiberAsyncTest.whenCancelRunBlockingInterruptExecutingThread() fails sometimes #266
Comments
Does the failure occur with the same frequency when the sleep time is increased to, say, 10s? This could be a simple timing issue. |
It seems that the test fails with similar frequency regardless of whether the Fiber sleeps for 1000ms or 10000ms. The reason seems to be a race-condition between interrupted.set(true) at the fiber and interrupted.get() at the outer caller. Apparently, It seems that the expected behavior is
As Fibers should implement cooperative multitasking with predictable scheduling properties, option (1) seems to be undesirable and option (2) seems to be desirable, but the decision of what should be correct behavior is up to you. |
On which line does the test fail? Are you sure the fiber has started executing? |
When executing this code: // @Ignore // FIXME: This test currently fails and needs to be investigated.
@Test
public void whenCancelRunBlockingInterruptExecutingThread() throws Exception {
for (int i = 0;i<100;i++) {
System.out.println("i="+i+".");
final AtomicBoolean started = new AtomicBoolean();
final AtomicBoolean interrupted = new AtomicBoolean();
Fiber fiber = new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
FiberAsync.runBlocking(Executors.newSingleThreadExecutor(),
new CheckedCallable<Void, RuntimeException>() {
@Override
public Void call() throws RuntimeException {
System.out.println("inner: starting.");
started.set(true);
System.out.println("inner: started.");
try {
System.out.println("inner: sleeping.");
Thread.sleep(10000);
System.out.println("inner: sleeped.");
} catch (InterruptedException e) {
System.out.println("inner: setting interrupted.");
interrupted.set(true);
System.out.println("inner: set interrupted.");
}
return null;
}
});
}
});
fiber.start();
Thread.sleep(100);
fiber.cancel(true);
try {
System.out.println("outer: joining.");
fiber.join(5, TimeUnit.MILLISECONDS);
System.out.println("outer: joined.");
fail("InterruptedException not thrown");
} catch(ExecutionException e) {
System.out.println("outer: caught "+e+".");
// e.printStackTrace();
if (!(e.getCause() instanceof InterruptedException))
fail("InterruptedException not thrown");
}
System.out.println("outer: reading started.");
assertThat(started.get(), is(true));
System.out.println("outer: reading interrupted.");
assertThat(interrupted.get(), is(true)); // line 366
}
} using commandline
So
At the line
Yes. |
Sorry, I completely spaced out on this one. What makes you think this is a bug at all? Obviously, the test is brittle, but there's no guarantee -- nor any need -- that the exception will be handled by the thread task by the time the fiber is joined. Normally, one does not wait for a canceled task to complete. |
When running the test FiberAsyncTest.whenCancelRunBlockingInterruptExecutingThread() as of https://github.com/puniverse/quasar/commits/df07c60aeccf3aacc3c0bd3534d1bba01ca50b72 repeatedly, it fails, while it should not fail.
The text was updated successfully, but these errors were encountered: