Fixed issue: #81

This commit is contained in:
UnlegitDqrk
2026-03-02 14:07:54 +01:00
parent ff4033cad4
commit c8fdc62495
3 changed files with 30 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ package org.luaj.vm2;
import java.io.Reader;
import java.io.StringReader;
import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -162,6 +163,32 @@ public class FragmentsTest extends TestSuite {
"return ok\n");
}
public void testInterruptedThreadStopsRunningClosure() throws Exception {
final Globals globals = JsePlatform.debugGlobals();
final LuaValue chunk = globals.load("while true do end", "interrupt.lua");
final AtomicReference<Throwable> thrown = new AtomicReference<Throwable>();
Thread t = new Thread(new Runnable() {
public void run() {
try {
chunk.call();
} catch (Throwable e) {
thrown.set(e);
}
}
}, "luaj-interrupt-test");
t.start();
Thread.sleep(50);
t.interrupt();
t.join(2000);
assertFalse("lua thread should stop after interrupt", t.isAlive());
assertNotNull("expected LuaError from interrupt", thrown.get());
assertEquals(LuaError.class, thrown.get().getClass());
assertEquals("interrupted", thrown.get().getMessage());
}
public void testLongIntegerLiteralPrecision() {
runFragment(
LuaValue.varargsOf(new LuaValue[] {