Fix crafting test simulation timing (#1645)

This commit is contained in:
Worive authored and GitHub committed 2026-09-20 15:56:46 +02:00
1 parent 7b732873e3
commit 4dcc31e510
1 file changed
+27 -27
@@ -42,7 +42,7 @@ public class CraftingV2Tests {
static World dummyWorld = null;
static boolean mixedMetalTestRecipeRegistered = false;
final int SIMPLE_SIMULATION_TIMEOUT_MS = 150;
final int MAX_SIMULATION_STEPS = 10_000;
final ItemStack bronzePlate, bronzeDoublePlate, bronzeIngot, gtHammer, singleUseGtHammer;
final ItemStack ironDust, ironIngot, ironPlate, goldDust, goldIngot, goldBlock;
@@ -92,8 +92,8 @@ public class CraftingV2Tests {
return stack;
}
private void simulateJobAndCheck(CraftingJobV2 job, int timeoutMs) {
job.simulateFor(timeoutMs);
private void simulateJobAndCheck(CraftingJobV2 job, int maxSteps) {
for (int step = 0; step < maxSteps && job.simulateFor(0); step++) {}
assertTrue(job.isDone());
assertFalse(job.isCancelled());
@@ -151,7 +151,7 @@ public class CraftingV2Tests {
void noPatternSimulation() {
MockAESystem aeSystem = new MockAESystem(dummyWorld);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.stick, 13));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertTrue(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Items.stick, 13)));
assertJobPlanEquals(job, AEItemStack.create(new ItemStack(Items.stick, 13)));
@@ -166,7 +166,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.stick, 13));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertTrue(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Items.stick, 13)));
assertJobPlanEquals(
@@ -182,7 +182,7 @@ public class CraftingV2Tests {
aeSystem.addStoredItem(new ItemStack(Items.diamond, 64));
aeSystem.addStoredItem(new ItemStack(Items.gold_ingot, 64));
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.stick, 13));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertTrue(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Items.stick, 13)));
assertJobPlanEquals(job, AEItemStack.create(new ItemStack(Items.stick, 13)));
@@ -199,7 +199,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.stick, 13));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Items.stick, 13)));
assertJobPlanEquals(
@@ -258,7 +258,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.chest, 1));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Blocks.chest, 1)));
assertJobPlanEquals(
@@ -279,7 +279,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.chest, 1));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Blocks.chest, 1)));
assertJobPlanEquals(
@@ -302,7 +302,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.bed, 1));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Items.bed, 1)));
assertJobPlanEquals(
@@ -324,7 +324,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.chest, 4));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Blocks.chest, 4)));
assertJobPlanEquals(
@@ -345,7 +345,7 @@ public class CraftingV2Tests {
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.chest, 4));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertTrue(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(new ItemStack(Blocks.chest, 4)));
assertJobPlanEquals(
@@ -365,7 +365,7 @@ public class CraftingV2Tests {
.addOutput(new ItemStack(Blocks.log, 1)).buildAndAdd();
for (int plankAmount = 1; plankAmount < 64; plankAmount++) {
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.planks, plankAmount));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(job.isSimulation(), plankAmount > 16);
}
}
@@ -378,7 +378,7 @@ public class CraftingV2Tests {
.addOutput(new ItemStack(Blocks.planks, 4)).allowBeingASubstitute().buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.planks, 1));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(true, job.isSimulation()); // Don't use renamed items
}
@@ -442,7 +442,7 @@ public class CraftingV2Tests {
addHammerBronzePlateRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(bronzePlate);
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(false, job.isSimulation());
assertJobPlanEquals(
job,
@@ -459,7 +459,7 @@ public class CraftingV2Tests {
addHammerBronzePlateRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(bronzePlate.copy(), 2));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(false, job.isSimulation());
assertJobPlanEquals(
job,
@@ -481,7 +481,7 @@ public class CraftingV2Tests {
addMixedMetalRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(getMixedMetalIngot(), 100));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(false, job.isSimulation());
assertJobPlanEquals(
job,
@@ -504,7 +504,7 @@ public class CraftingV2Tests {
addHammerBronzeDoublePlateRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(bronzeDoublePlate);
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(false, job.isSimulation());
assertJobPlanEquals(
job,
@@ -522,7 +522,7 @@ public class CraftingV2Tests {
addHammerBronzePlateRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(bronzePlate.copy(), 2));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(true, job.isSimulation());
assertJobPlanEquals(
job,
@@ -539,7 +539,7 @@ public class CraftingV2Tests {
.buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(bronzeDoublePlate.copy(), 1));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(true, job.isSimulation());
assertJobPlanEquals(
job,
@@ -556,7 +556,7 @@ public class CraftingV2Tests {
.addOutput(new ItemStack(Blocks.gold_block)).buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.gold_block, 100));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(true, job.isSimulation());
assertJobPlanEquals(
job,
@@ -586,7 +586,7 @@ public class CraftingV2Tests {
.buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.gold_block, 100));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertEquals(true, job.isSimulation());
assertJobPlanEquals(
job,
@@ -615,7 +615,7 @@ public class CraftingV2Tests {
.buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(ironPlate, 3));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(withSize(ironPlate, 3)));
assertJobPlanEquals(
@@ -626,7 +626,7 @@ public class CraftingV2Tests {
AEItemStack.create(withSize(ironPlate, 0)).setCountRequestable(3));
final CraftingJobV2 jobFailed = aeSystem.makeCraftingJob(withSize(ironPlate, 4));
simulateJobAndCheck(jobFailed, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(jobFailed, MAX_SIMULATION_STEPS);
assertTrue(jobFailed.isSimulation());
assertJobPlanEquals(
jobFailed,
@@ -656,7 +656,7 @@ public class CraftingV2Tests {
.buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(ironPlate, 3));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
assertEquals(job.getOutput(), AEItemStack.create(withSize(ironPlate, 3)));
assertJobPlanEquals(
@@ -668,7 +668,7 @@ public class CraftingV2Tests {
AEItemStack.create(withSize(ironPlate, 0)).setCountRequestable(3));
final CraftingJobV2 jobFailed = aeSystem.makeCraftingJob(withSize(ironPlate, 4));
simulateJobAndCheck(jobFailed, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(jobFailed, MAX_SIMULATION_STEPS);
assertTrue(jobFailed.isSimulation());
assertJobPlanEquals(
jobFailed,
@@ -699,7 +699,7 @@ public class CraftingV2Tests {
.buildAndAdd();
final CraftingJobV2 job = aeSystem.makeCraftingJob(withSize(ironPlate, 3));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
simulateJobAndCheck(job, MAX_SIMULATION_STEPS);
assertFalse(job.isSimulation());
final List<CraftingRequest> goldIngotRequests = getMatchingRequests(job, withSize(goldIngot.copy(), 1));