Skip to content

Commit

Permalink
Fix running integration tests from IDEA
Browse files Browse the repository at this point in the history
also fix the integration test server's world gen settings.
  • Loading branch information
bziemons committed Feb 21, 2023
1 parent d624802 commit d795c74
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
28 changes: 26 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ minecraft {

// put LP in test mode
property 'logisticspipes.test', 'true'
property 'logisticspipes.test.debug', 'false' // set this to true in the generated run configuration

lazyToken 'classpathExclude', {
def paths = [
sourceSets.main.output.classesDirs.asPath,
sourceSets.api.output.classesDirs.asPath,
sourceSets.main.output.resourcesDir.path,
sourceSets.api.output.resourcesDir.path,
]
String.join(File.pathSeparator, paths)
}
lazyToken 'classpathInclude', {
def paths = [
"${project.buildDir}/run_classes/",
sourceSets.test.output.classesDirs.asPath,
sourceSets.test.output.resourcesDir.path,
]
// sorry for the mess in the run configuration's classpath,
// but using the test classpath included the dependencies from the provided scope
for (final def file in configurations.testRuntimeClasspath.resolvedConfiguration.files) {
paths.add(file.toPath().toString())
}
String.join(File.pathSeparator, paths)
}

mods {
logisticspipes {
Expand Down Expand Up @@ -284,7 +308,7 @@ task sourceJar(type: Jar) {

test {
reports {
html.enabled = true
html.required.set(true)
}
}

Expand Down Expand Up @@ -515,7 +539,7 @@ gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
properties.setProperty('online-mode', 'false')
properties.setProperty('gamemode', '1')
properties.setProperty('level-type', 'FLAT')
properties.setProperty('generator-settings', 'minecraft:bedrock,3*minecraft:stone,52*minecraft:sandstone;minecraft:desert;')
properties.setProperty('generator-settings', '3;minecraft:bedrock,3*minecraft:stone,96*minecraft:sandstone;2;')
properties.setProperty('motd', 'Logistics Pipes Test Server')
//properties.setProperty('max-tick-time', '0') // for debugging the server
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,31 @@

package network.rs485.logisticspipes.integration

import kotlinx.coroutines.*
import kotlinx.coroutines.time.withTimeout
import network.rs485.grow.Coroutines
import logisticspipes.LogisticsPipes
import net.minecraft.server.dedicated.DedicatedServer
import net.minecraft.world.WorldServer
import net.minecraftforge.fml.common.FMLCommonHandler
import net.minecraftforge.fml.common.event.FMLServerStartedEvent
import network.rs485.grow.Coroutines
import net.minecraft.server.dedicated.DedicatedServer
import net.minecraft.util.math.BlockPos
import net.minecraft.world.WorldServer
import java.lang.management.ManagementFactory
import java.time.Duration
import kotlin.test.assertTrue
import kotlinx.coroutines.*
import kotlinx.coroutines.time.withTimeout

@Suppress("unused", "MemberVisibilityCanBePrivate")
object MinecraftTest {

/**
* If not debugging, the server watch dog is not disabled and the server is shut down after running the tests.
*/
private const val DEBUGGING = false
private val DEBUGGING = System.getProperties().getProperty("logisticspipes.test.debug").let { prop ->
prop?.equals("true", ignoreCase = true) == true
}

private lateinit var world: WorldServer
private lateinit var firstBlockPos: BlockPos
private lateinit var testBlockBuilder: TestWorldBuilder

const val TIMEOUT_MODIFIER: Long = 1L
Expand All @@ -73,6 +78,9 @@ object MinecraftTest {
if (watchdog != null) error("Watchdog already running! Set max-tick-time to 0, please restart the server!")
}
world = serverInstance.worlds[0]
firstBlockPos = BlockPos(0, LEVEL, 0)
world.spawnPoint = firstBlockPos
world.gameRules.setOrCreateGameRule("spawnRadius", "0")
val task = startTests(LogisticsPipes.log::info)
task.invokeOnCompletion {
if (it != null) throw it
Expand All @@ -88,7 +96,8 @@ object MinecraftTest {
delay(Duration.ofSeconds(1 * TIMEOUT_MODIFIER).toMillis())
println("[STARTING LOGISTICSPIPES TESTS]")
withTimeout(Duration.ofMinutes(3)) {
testBlockBuilder = TestWorldBuilder(world)
testBlockBuilder = TestWorldBuilder(world, firstBlockPos)
world.spawnPoint = testBlockBuilder.buildSpawnPlatform()
listOf(
async {
CraftingTest.`test fuzzy-input crafting succeeds multi-request with mixed input OreDict`(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ import kotlin.math.min
const val LEVEL = 100
val ONE_VECTOR = Vec3i(1, 1, 1)

class TestWorldBuilder(override val world: WorldServer) : WorldBuilder {
class TestWorldBuilder(override val world: WorldServer, val firstBlockPos: BlockPos) : WorldBuilder {

private val selectors = ArrayList<Pair<BlockPosSelector, BlockPos>>()

// TODO: grouping and expanding groups in z needs collecting all selectors/builds before configuration
private var nextPos = BlockPos(0, LEVEL, 0)
private var nextPos = firstBlockPos
private var lowest = LEVEL

private val tickets: HashSet<ForgeChunkManager.Ticket> = HashSet()
Expand Down Expand Up @@ -113,6 +113,16 @@ class TestWorldBuilder(override val world: WorldServer) : WorldBuilder {
if (chunksToLoad.add(pos)) ForgeChunkManager.forceChunk(tickets.first(), pos)
}

fun buildSpawnPlatform(): BlockPos {
val start = firstBlockPos.subtract(ONE_VECTOR)
world.setBlocks(
start = BlockPos(start.x - 5, start.y, start.z),
end = BlockPos(start.x - 1, start.y, start.z + 4),
state = Blocks.OBSIDIAN.defaultState,
)
return BlockPos(start.x - 3, firstBlockPos.y, start.z + 2)
}

}

private fun WorldServer.setBlocks(start: BlockPos, end: BlockPos, state: IBlockState) =
Expand Down

0 comments on commit d795c74

Please sign in to comment.