Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Test logic when exception is thrown in thread
Dieser Commit ist enthalten in:
Ursprung
3b5d20e62d
Commit
c30cc66461
@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ -33,4 +34,36 @@ class RecordingThreadFactoryTest {
|
||||
Thread.sleep(10);
|
||||
assertEquals(0, factory.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanUpAfterExceptionThrown() throws Exception {
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
CountDownLatch endThread = new CountDownLatch(1);
|
||||
CountDownLatch hasEnded = new CountDownLatch(1);
|
||||
RecordingThreadFactory factory = new RecordingThreadFactory((ThreadFactory) r -> {
|
||||
Thread t = new Thread(r);
|
||||
t.setUncaughtExceptionHandler((t1, e) -> hasEnded.countDown());
|
||||
return t;
|
||||
});
|
||||
factory.newThread(() -> {
|
||||
started.countDown();
|
||||
assertTrue(factory.currentlyInFactory());
|
||||
assertEquals(1, factory.size());
|
||||
try {
|
||||
endThread.await();
|
||||
} catch (InterruptedException e) {
|
||||
fail(e);
|
||||
}
|
||||
throw new RuntimeException("");
|
||||
}).start();
|
||||
started.await();
|
||||
assertFalse(factory.currentlyInFactory());
|
||||
assertEquals(1, factory.size());
|
||||
endThread.countDown();
|
||||
hasEnded.await();
|
||||
|
||||
// Wait a little bit to ensure the thread got shut down
|
||||
Thread.sleep(10);
|
||||
assertEquals(0, factory.size());
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren