Close modded engines per level at unload and in a stopped phase

Server stopping used to close engines, mantle and the generation pools while the loader was still draining chunk generation. Stopping now tears down the services only; the engines and pools close at server stopped, a failed level unload is logged instead of aborting the loader's close loop, and a sweep at the next server start or JVM exit covers a loader that skips the stopped event.

Upstream: 259f88523 782a85c26
This commit is contained in:
piexel committed 2026-11-10 01:07:00 +01:00
1 parent b0f535832e
commit bed98c417d
9 files changed
+192 -26

No files matched your search

@@ -0,0 +1,88 @@
package art.arcane.iris.modded;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.modded.command.IrisModdedCommands;
import art.arcane.iris.util.common.parallel.MultiBurst;
import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.MinecraftServer;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.MockedStatic;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
public class ModdedEngineBootstrapShutdownTest {
private static final long WORKER_TIMEOUT_SECONDS = 10L;
private static final Callable<Thread> RUNNING_THREAD = Thread::currentThread;
private IrisSettings previousSettings;
@BeforeClass
public static void bootstrapMinecraftRegistries() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
}
@Before
public void openRuntime() {
previousSettings = IrisSettings.settings;
IrisSettings.settings = new IrisSettings();
reopenBurstPools();
}
@After
public void restoreRuntime() {
reopenBurstPools();
IrisModdedCommands.openDownloadAdmission();
IrisSettings.settings = previousSettings;
}
@Test
public void serverStoppingKeepsTheGenerationPoolsOpenUntilServerStopped() throws Exception {
ModdedEngineBootstrap.stop();
assertNotSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
ModdedEngineBootstrap.stopped();
assertSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
}
@Test
public void nextServerStartClosesWhatAServerThatNeverReachedStoppedLeftOpen() throws Exception {
ModdedEngineBootstrap.stop();
try (MockedStatic<ModdedStartup> startup = mockStatic(ModdedStartup.class)) {
ModdedEngineBootstrap.serverAboutToStart(mock(MinecraftServer.class));
}
assertSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
}
@Test
public void serverStartLeavesTheGenerationPoolsAloneWhenTheServerStoppedNormally() throws Exception {
ModdedEngineBootstrap.stop();
ModdedEngineBootstrap.stopped();
MultiBurst.burst.reopen();
try (MockedStatic<ModdedStartup> startup = mockStatic(ModdedStartup.class)) {
ModdedEngineBootstrap.serverAboutToStart(mock(MinecraftServer.class));
}
assertNotSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
}
private static void reopenBurstPools() {
MultiBurst.burst.reopen();
MultiBurst.ioBurst.reopen();
}
}
@@ -120,10 +120,10 @@ public class ModdedGenerationLeaseContractTest {
String bootstrap = source("art/arcane/iris/modded/ModdedEngineBootstrap.java");
String stop = method(bootstrap, "public static void stop()");
int downloads = stop.indexOf("IrisModdedCommands::shutdownDownloads");
int scheduler = stop.indexOf("scheduler::shutdown");
assertTrue(downloads >= 0);
assertTrue(scheduler > downloads);
assertTrue(stop.contains("IrisModdedCommands::shutdownDownloads"));
assertFalse(stop.contains("scheduler::shutdown"));
String stopped = method(bootstrap, "private static void closeStoppedServer()");
assertTrue(stopped.contains("scheduler::shutdown"));
}
@Test
@@ -141,21 +141,27 @@ public class ModdedLifecycleFailureContractTest {
@Test
public void engineBootstrapResetsStartupExactlyOnceDuringStop() throws IOException {
String source = source("ModdedEngineBootstrap.java");
String stop = method(source, "public static void stop(");
String stopped = method(source, "private static void closeStoppedServer(");
assertEquals(1, occurrences(stop, "ModdedStartup::reset"));
assertEquals(1, occurrences(source, "ModdedStartup::reset"));
assertEquals(1, occurrences(stopped, "ModdedStartup::reset"));
}
@Test
public void engineBootstrapAttemptsEveryShutdownStageAndAggregatesFailures() throws IOException {
String source = source("ModdedEngineBootstrap.java");
String stop = method(source, "public static void stop(");
String stopped = method(source, "private static void closeStoppedServer(");
assertBefore(stop, "\"services\"", "\"world engines\"");
assertBefore(stop, "\"world engines\"", "\"dimension manager\"");
assertBefore(stop, "\"server state\"", "if (failure != null)");
assertTrue(stop.contains("\"services\""));
assertFalse(stop.contains("\"world engines\""));
assertBefore(stopped, "\"world engines\"", "\"dimension manager\"");
assertBefore(stopped, "\"server state\"", "reportStopFailure(\"stopped\", failure);");
assertBefore(stop, "\"services\"", "reportStopFailure(\"stopping\", failure);");
assertFalse(stop.contains("throw"));
assertTrue(stop.contains("ModdedIrisLog.error(\"Iris modded shutdown completed with failures\", failure);"));
assertFalse(stopped.contains("throw"));
String report = method(source, "private static void reportStopFailure(");
assertTrue(report.contains("ModdedIrisLog.error(\"Iris modded shutdown ({}) completed with failures\", phase, failure);"));
String runStage = method(source, "private static Throwable runStopStage(");
assertTrue(runStage.contains("catch (Throwable stageFailure)"));
@@ -206,12 +212,12 @@ public class ModdedLifecycleFailureContractTest {
}
@Test
public void loaderUnloadSurfacesCloseFailureAndDynamicRemovalUsesStrictEviction() throws IOException {
public void loaderUnloadLogsCloseFailureAndDynamicRemovalUsesStrictEviction() throws IOException {
String bootstrapSource = source("ModdedEngineBootstrap.java");
String unload = method(bootstrapSource, "public static void levelUnloaded(ServerLevel level)");
String failure = catchBlock(unload);
assertTrue(failure.contains("ModdedIrisLog.error("));
assertTrue(failure.contains("throw "));
assertFalse(failure.contains("throw "));
String managerSource = source("ModdedDimensionManager.java");
String remove = method(managerSource, "public static boolean remove(MinecraftServer server, String dimensionId, boolean wipeStorage)");