Skip to content

Commit cb36e7a

Browse files
committed
Test cancellation with Fibers
1 parent 10d68c7 commit cb36e7a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/org/truffleruby/MiscTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,31 @@ public void timeoutExecution() throws Throwable {
6464
}
6565
}
6666

67+
@Test
68+
public void testCancellationWithFibers() throws Throwable {
69+
Context context = RubyTest.createContext();
70+
71+
// schedule a timeout in 100ms
72+
TestingThread thread = new TestingThread(() -> {
73+
try {
74+
Thread.sleep(100);
75+
} catch (InterruptedException e) {
76+
throw new Error(e);
77+
}
78+
context.close(true);
79+
});
80+
81+
context.eval("ruby", "init = 1");
82+
thread.start();
83+
try {
84+
String code = "unstarted = Fiber.new {}; resumed = Fiber.new { Fiber.yield }.tap(&:resume); sleep 1";
85+
RubyTest.assertThrows(() -> context.eval("ruby", code),
86+
e -> assertTrue(e.isCancelled()));
87+
} finally {
88+
thread.join();
89+
}
90+
}
91+
6792
@Test
6893
public void testEvalFromIntegratorThreadSingleThreaded() throws Throwable {
6994
final String codeDependingOnCurrentThread = "Thread.current.object_id";

0 commit comments

Comments
 (0)