Fix Iris replacement

This commit is contained in:
Brian Neumann-Fopiano committed 2026-08-15 15:58:07 -04:00
1 parent 4568b3fff1
commit 8297e49ed2
52 files changed
+4748 -198

No files matched your search

@@ -86,6 +86,60 @@ public class ModdedGenerationLeaseContractTest {
assertTrue(source.contains("active.awaitTermination(INTERRUPT_DRAIN_TIMEOUT_SECONDS, TimeUnit.SECONDS)"));
}
@Test
public void packDownloadAdmissionPrecedesAsyncDispatch() throws IOException {
String source = source("art/arcane/iris/modded/command/IrisModdedCommands.java");
String download = method(source, "static int download(CommandSourceStack source, String rawRequest)");
int admission = download.indexOf("LifecycleOperationCoordinator.get().acquire(");
int executionTracking = download.indexOf("new PackDownloadExecution(");
int dispatch = download.indexOf("scheduler.asyncIfRunning(execution, execution::cancel)");
assertTrue(admission >= 0);
assertTrue(executionTracking > admission);
assertTrue(dispatch > admission);
assertTrue(download.contains("execution.cancel();"));
String execution = method(source, "private static void executeDownload(");
assertTrue(execution.contains("PackDownloader.DownloadCancellation cancellation"));
assertTrue(execution.contains("catch (PackDownloader.PackDownloadCancelledException error)"));
assertFalse(execution.contains("lease.close();"));
}
@Test
public void packDownloadsDrainBeforeModdedSchedulerShutdown() throws IOException {
String commands = source("art/arcane/iris/modded/command/IrisModdedCommands.java");
String shutdownDownloads = method(commands, "public static void shutdownDownloads()");
assertTrue(shutdownDownloads.contains("downloadAdmissionOpen = false;"));
assertTrue(shutdownDownloads.contains("execution.cancel();"));
assertTrue(shutdownDownloads.contains("execution.await("));
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);
}
@Test
public void moddedSchedulerRejectsAndCancelsAbandonedDownloadSubmissions() throws IOException {
String scheduler = source("art/arcane/iris/modded/ModdedScheduler.java");
String dispatch = method(scheduler, "public boolean asyncIfRunning(Runnable task, Runnable rejection)");
assertTrue(dispatch.contains("RejectionAwareTask"));
assertTrue(dispatch.contains("Objects.requireNonNull(rejection"));
String shutdown = method(scheduler, "public void shutdown()");
assertTrue(shutdown.contains("asyncExecutor.shutdownNow()"));
assertTrue(shutdown.contains("rejectAbandonedTasks(abandonedTasks);"));
String reset = method(scheduler, "public void reset()");
assertTrue(reset.contains("asyncExecutor.getQueue().drainTo(abandonedTasks);"));
assertTrue(reset.contains("rejectAbandonedTasks(abandonedTasks);"));
String rejection = method(scheduler, "private static void rejectAbandonedTasks(");
assertTrue(rejection.contains("rejectionAwareTask.reject();"));
}
@Test
public void blockingPregenShutdownDefersItsFinalSaveToTheServerThread() throws IOException {
String jobSource = source("art/arcane/iris/modded/command/ModdedPregenJob.java");
@@ -0,0 +1,110 @@
package art.arcane.iris.modded;
import art.arcane.iris.core.lifecycle.LifecycleOperationCoordinator;
import art.arcane.iris.core.pack.PackDownloadExecution;
import org.junit.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedSchedulerDownloadCancellationTest {
@Test
public void rejectedDownloadSubmissionReleasesItsLease() throws Exception {
ModdedScheduler scheduler = new ModdedScheduler();
scheduler.shutdown();
TestLease lease = new TestLease();
AtomicBoolean ran = new AtomicBoolean();
PackDownloadExecution execution = new PackDownloadExecution(
lease,
cancellation -> ran.set(true)
);
boolean accepted = scheduler.asyncIfRunning(execution, execution::cancel);
assertFalse(accepted);
assertTrue(execution.await(1L, TimeUnit.SECONDS));
assertFalse(ran.get());
assertEquals(1, lease.closeCount());
}
@Test
public void schedulerShutdownCancelsQueuedDownloadAndReleasesItsLease() throws Exception {
ModdedScheduler scheduler = new ModdedScheduler();
int workerCount = Math.max(4, Runtime.getRuntime().availableProcessors());
CountDownLatch workersStarted = new CountDownLatch(workerCount);
CountDownLatch releaseWorkers = new CountDownLatch(1);
for (int index = 0; index < workerCount; index++) {
scheduler.async(() -> {
workersStarted.countDown();
try {
releaseWorkers.await();
} catch (InterruptedException exception) {
Thread.currentThread().interrupt();
}
});
}
assertTrue(workersStarted.await(10L, TimeUnit.SECONDS));
TestLease lease = new TestLease();
AtomicBoolean ran = new AtomicBoolean();
PackDownloadExecution execution = new PackDownloadExecution(
lease,
cancellation -> ran.set(true)
);
assertTrue(scheduler.asyncIfRunning(execution, execution::cancel));
try {
scheduler.shutdown();
assertTrue(execution.await(5L, TimeUnit.SECONDS));
assertFalse(ran.get());
assertEquals(1, lease.closeCount());
} finally {
releaseWorkers.countDown();
scheduler.shutdown();
}
}
private static final class TestLease implements LifecycleOperationCoordinator.Lease {
private final LifecycleOperationCoordinator.ActiveOperation operation;
private final AtomicBoolean closed;
private final AtomicInteger closeCount;
private TestLease() {
operation = new LifecycleOperationCoordinator.ActiveOperation(
1L,
LifecycleOperationCoordinator.Domain.PACK_MUTATION,
LifecycleOperationCoordinator.OperationKind.PACK_DOWNLOAD,
"test"
);
closed = new AtomicBoolean();
closeCount = new AtomicInteger();
}
@Override
public LifecycleOperationCoordinator.ActiveOperation operation() {
return operation;
}
@Override
public boolean isClosed() {
return closed.get();
}
@Override
public void close() {
closeCount.incrementAndGet();
closed.set(true);
}
private int closeCount() {
return closeCount.get();
}
}
}
@@ -1,5 +1,9 @@
package art.arcane.iris.modded.command;
import art.arcane.iris.core.localization.IrisLanguage;
import art.arcane.iris.core.localization.PackDownloadMessages;
import art.arcane.iris.core.lifecycle.LifecycleOperationCoordinator;
import art.arcane.iris.core.pack.PackDownloader;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.CommandNode;
import net.minecraft.SharedConstants;
@@ -9,10 +13,11 @@ import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class IrisModdedCommandParityTest {
@@ -73,6 +78,9 @@ public class IrisModdedCommandParityTest {
assertEquals("underworld", underworld.pack());
assertNotNull(link);
assertEquals("https://packs.example.test/custom.zip?token=a=b", link.url());
String displayTarget = IrisModdedCommands.downloadDisplayTarget(link);
assertEquals(IrisLanguage.plain(PackDownloadMessages.PROGRESS_SOURCE_REMOTE), displayTarget);
assertFalse(displayTarget.contains("token"));
assertNull(IrisModdedCommands.parseDownloadRequest("overworld"));
assertNull(IrisModdedCommands.parseDownloadRequest("pack=custom"));
assertNull(IrisModdedCommands.parseDownloadRequest("link=https://packs.example.test/custom.tar.gz"));
@@ -80,6 +88,51 @@ public class IrisModdedCommandParityTest {
assertNull(IrisModdedCommands.parseDownloadRequest("pack=underworld overwrite=true"));
}
@Test
public void downloadCompletionMessageOnlyReportsActualPackChanges() {
assertEquals(
"Pack installed on disk. Restart the server before using it.",
IrisModdedCommands.downloadCompletionMessage(
new PackDownloader.PackInstallResult("overworld", true, true)
)
);
assertEquals(
"Pack installed on disk.",
IrisModdedCommands.downloadCompletionMessage(
new PackDownloader.PackInstallResult("overworld", true, false)
)
);
assertNull(IrisModdedCommands.downloadCompletionMessage(
new PackDownloader.PackInstallResult("overworld", false, false)
));
assertNull(IrisModdedCommands.downloadCompletionMessage(null));
}
@Test
public void downloadBusyMessageDistinguishesPackDownloadsFromOtherLifecycleWork() {
LifecycleOperationCoordinator.ActiveOperation packDownload = new LifecycleOperationCoordinator.ActiveOperation(
1L,
LifecycleOperationCoordinator.Domain.PACK_MUTATION,
LifecycleOperationCoordinator.OperationKind.PACK_DOWNLOAD,
"overworld"
);
LifecycleOperationCoordinator.ActiveOperation worldCreation = new LifecycleOperationCoordinator.ActiveOperation(
2L,
LifecycleOperationCoordinator.Domain.WORLD_MUTATION,
LifecycleOperationCoordinator.OperationKind.WORLD_CREATE,
"iris_world"
);
assertEquals(
IrisLanguage.plain(PackDownloadMessages.IN_PROGRESS),
IrisModdedCommands.downloadBusyMessage(packDownload)
);
assertEquals(
"Iris pack changes are busy with world_create for 'iris_world'. Try again when it completes.",
IrisModdedCommands.downloadBusyMessage(worldCreation)
);
}
@Test
public void helpDocumentsParityCommandsAndPlatformStubs() {
assertTrue(ModdedCommandHelp.documents("what", "here"));