-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop using Guava RateLimiter as the gametests run ticks faster, and the RateLimiter uses the system clock so RS wouldn't keep up with the faster tick rate.
- Loading branch information
1 parent
33d83f0
commit a283a03
Showing
13 changed files
with
217 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...m-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.refinedmods.refinedstorage2.platform.forge; | ||
|
||
import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage2.platform.common.constructordestructor.ConstructorBlockEntity; | ||
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.core.Direction; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
import net.neoforged.testframework.gametest.ExtendedGameTestHelper; | ||
|
||
import static com.refinedmods.refinedstorage2.platform.forge.TestMod.DIRT; | ||
import static com.refinedmods.refinedstorage2.platform.forge.TestMod.RSBLOCKS; | ||
import static com.refinedmods.refinedstorage2.platform.forge.TestMod.itemIsInserted; | ||
import static com.refinedmods.refinedstorage2.platform.forge.TestMod.storageMustContainExactly; | ||
import static net.minecraft.core.BlockPos.ZERO; | ||
|
||
public final class ConstructorTest { | ||
private ConstructorTest() { | ||
} | ||
|
||
@GameTest | ||
@EmptyTemplate(value = "5x5x5", floor = true) | ||
@TestHolder(description = "Tests whether the Constructor can place a block") | ||
public static void shouldPlaceBlock(final ExtendedGameTestHelper helper) { | ||
// Arrange | ||
helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); | ||
helper.setBlock(ZERO.above().above(), RSBLOCKS.getConstructor().getDefault().rotated(Direction.EAST)); | ||
helper.setBlock( | ||
ZERO.above().above().above(), | ||
RSBLOCKS.getItemStorageBlock(ItemStorageType.Variant.ONE_K) | ||
); | ||
|
||
final var seq = helper.startSequence(); | ||
seq.thenWaitUntil(itemIsInserted(helper, ZERO.above().above(), DIRT, 10)); | ||
|
||
// Act | ||
helper.requireBlockEntity(ZERO.above().above(), ConstructorBlockEntity.class).setFilters(List.of(DIRT)); | ||
|
||
// Assert | ||
seq.thenWaitUntil(() -> helper.assertBlockPresent(Blocks.DIRT, ZERO.above().above().east())) | ||
.thenWaitUntil(storageMustContainExactly(helper, ZERO.above().above(), new ResourceAmount(DIRT, 9))) | ||
.thenSucceed(); | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
...-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ExporterGameTest.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
...-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/TestMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.refinedmods.refinedstorage2.platform.forge; | ||
|
||
import com.refinedmods.refinedstorage2.api.core.Action; | ||
import com.refinedmods.refinedstorage2.api.network.Network; | ||
import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; | ||
import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; | ||
import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage2.api.storage.EmptyActor; | ||
import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; | ||
import com.refinedmods.refinedstorage2.platform.common.content.Blocks; | ||
import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; | ||
import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; | ||
|
||
import java.util.Arrays; | ||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTestAssertException; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.fml.ModLoadingContext; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.testframework.conf.FrameworkConfiguration; | ||
import net.neoforged.testframework.gametest.ExtendedGameTestHelper; | ||
|
||
@Mod(TestMod.ID) | ||
public class TestMod { | ||
public static final String ID = IdentifierUtil.MOD_ID + "_tests"; | ||
|
||
public static final ItemResource DIRT = ItemResource.ofItemStack(new ItemStack(Items.DIRT)); | ||
public static final Blocks RSBLOCKS = Blocks.INSTANCE; | ||
|
||
public TestMod(final IEventBus eventBus) { | ||
final var framework = FrameworkConfiguration.builder(new ResourceLocation(ID, "tests")) | ||
.build() | ||
.create(); | ||
framework.init(eventBus, ModLoadingContext.get().getActiveContainer()); | ||
} | ||
|
||
@Nullable | ||
public static Network getNetwork(final ExtendedGameTestHelper helper, final BlockPos pos) { | ||
try { | ||
final var be = helper.requireBlockEntity(pos, AbstractNetworkNodeContainerBlockEntity.class); | ||
final var field = AbstractNetworkNodeContainerBlockEntity.class.getDeclaredField("mainNode"); | ||
field.setAccessible(true); | ||
final NetworkNode mainNode = (NetworkNode) field.get(be); | ||
return mainNode.getNetwork(); | ||
} catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static Runnable itemIsInserted(final ExtendedGameTestHelper helper, | ||
final BlockPos networkPos, | ||
final ItemResource resource, | ||
final long amount) { | ||
return () -> { | ||
final Network network = getNetwork(helper, networkPos); | ||
helper.assertTrue(network != null && network.getComponent(StorageNetworkComponent.class) | ||
.insert(resource, amount, Action.EXECUTE, EmptyActor.INSTANCE) == amount, | ||
"Item couldn't be inserted" | ||
); | ||
}; | ||
} | ||
|
||
public static Runnable storageMustContainExactly(final ExtendedGameTestHelper helper, | ||
final BlockPos networkPos, | ||
final ResourceAmount... expected) { | ||
return () -> { | ||
final Network network = getNetwork(helper, networkPos); | ||
helper.assertTrue(network != null, "Network is not found"); | ||
if (network == null) { | ||
return; | ||
} | ||
final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); | ||
for (final ResourceAmount expectedItem : expected) { | ||
final boolean contains = storage.getAll() | ||
.stream() | ||
.anyMatch(inStorage -> inStorage.getResource().equals(expectedItem.getResource()) | ||
&& inStorage.getAmount() == expectedItem.getAmount()); | ||
if (!contains) { | ||
throw new GameTestAssertException("Missing from storage: " + expectedItem); | ||
} | ||
} | ||
for (final ResourceAmount inStorage : storage.getAll()) { | ||
final boolean wasExpected = Arrays.stream(expected).anyMatch( | ||
expectedItem -> expectedItem.getResource().equals(inStorage.getResource()) | ||
&& expectedItem.getAmount() == inStorage.getAmount() | ||
); | ||
if (!wasExpected) { | ||
throw new GameTestAssertException("Unexpected in storage: " + inStorage); | ||
} | ||
} | ||
}; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
refinedstorage2-platform-forge/src/test/resources/META-INF/mods.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
modLoader = "javafml" | ||
loaderVersion = "[2,)" | ||
license = "MIT" | ||
[[mods]] | ||
modId = "refinedstorage2" | ||
[[mods]] | ||
modId = "refinedstorage2_tests" |
Binary file removed
BIN
-8.26 KB
...torage2-platform-forge/src/test/resources/data/refinedstorage2/structures/empty_15x15.nbt
Binary file not shown.