From 162d0a97aa5b07b3122d451435d2dee117d70854 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Mon, 17 Oct 2022 19:57:26 +0200 Subject: [PATCH] integration tests --- build.gradle.kts | 84 ++++++++++++++++++- .../de/bixilon/minosoft/MinosoftSIT.kt} | 33 ++++++-- .../data/registries/versions/VersionsIT.kt | 7 +- .../de/bixilon/minosoft/setup/MinosoftSIT.kt | 30 ------- .../packets/factory/PacketTypeRegistry.kt | 2 +- 5 files changed, 114 insertions(+), 42 deletions(-) rename src/{integreation-test/kotlin/de/bixilon/minosoft/setup/data/registries/versions/VersionsSIT.kt => integration-test/kotlin/de/bixilon/minosoft/MinosoftSIT.kt} (59%) rename src/{integreation-test/kotlin/de/bixilon/minosoft/test => integration-test/kotlin/de/bixilon/minosoft}/data/registries/versions/VersionsIT.kt (84%) delete mode 100644 src/integreation-test/kotlin/de/bixilon/minosoft/setup/MinosoftSIT.kt diff --git a/build.gradle.kts b/build.gradle.kts index df69bb6e1..37dd727c9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,12 +14,14 @@ import de.bixilon.kutil.os.Architectures import de.bixilon.kutil.os.OSTypes import de.bixilon.kutil.os.PlatformInfo +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.api.tasks.testing.logging.TestLogEvent import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { kotlin("jvm") version "1.7.20" id("org.openjfx.javafxplugin") version "0.0.13" + `jvm-test-suite` application } @@ -120,6 +122,83 @@ when (PlatformInfo.OS) { } } +testing { + suites { + val test by getting(JvmTestSuite::class) { + useJUnitJupiter() + + targets { + all { + testTask.configure { + filter { + isFailOnNoMatchingTests = true + } + testLogging { + exceptionFormat = TestExceptionFormat.FULL + showExceptions = true + showStandardStreams = true + events( + TestLogEvent.PASSED, + TestLogEvent.FAILED, + TestLogEvent.SKIPPED, + TestLogEvent.STANDARD_OUT, + TestLogEvent.STANDARD_ERROR, + ) + } + } + } + } + } + + val integrationTest by registering(JvmTestSuite::class) { + testType.set(TestSuiteType.INTEGRATION_TEST) + useTestNG() + + dependencies { + implementation(project) + // implementation("org.jetbrains.kotlin:kotlin-test:1.7.20") + implementation("de.bixilon:kutil:$kutilVersion") + } + + targets { + all { + testTask.configure { + filter { + isFailOnNoMatchingTests = true + } + testLogging { + exceptionFormat = TestExceptionFormat.FULL + showExceptions = true + showStandardStreams = true + events( + TestLogEvent.PASSED, + TestLogEvent.FAILED, + TestLogEvent.SKIPPED, + TestLogEvent.STANDARD_OUT, + TestLogEvent.STANDARD_ERROR, + ) + } + options { + val options = this as TestNGOptions + options.preserveOrder = true + } + shouldRunAfter(test) + } + } + } + sources { + kotlin { + setSrcDirs(listOf("src/integration-test/kotlin")) + } + } + } + } +} + +tasks.named("check") { + dependsOn(testing.suites.named("integrationTest")) +} + fun DependencyHandler.javafx(name: String) { implementation("org.openjfx", "javafx-$name", javafxVersion, classifier = javafxNatives) } @@ -197,6 +276,8 @@ dependencies { // kotlin implementation(kotlin("reflect")) testImplementation(kotlin("test")) + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") // platform specific @@ -228,6 +309,7 @@ tasks.withType { application { mainClass.set("de.bixilon.minosoft.Minosoft") } + javafx { version = javafxVersion modules("javafx.controls", "javafx.fxml") diff --git a/src/integreation-test/kotlin/de/bixilon/minosoft/setup/data/registries/versions/VersionsSIT.kt b/src/integration-test/kotlin/de/bixilon/minosoft/MinosoftSIT.kt similarity index 59% rename from src/integreation-test/kotlin/de/bixilon/minosoft/setup/data/registries/versions/VersionsSIT.kt rename to src/integration-test/kotlin/de/bixilon/minosoft/MinosoftSIT.kt index d306e17bf..b82b86f6a 100644 --- a/src/integreation-test/kotlin/de/bixilon/minosoft/setup/data/registries/versions/VersionsSIT.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/MinosoftSIT.kt @@ -11,17 +11,38 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.setup.data.registries.versions +package de.bixilon.minosoft import de.bixilon.kutil.latch.CountUpAndDownLatch import de.bixilon.minosoft.data.registries.versions.Versions -import org.junit.jupiter.api.Order -import org.junit.jupiter.api.Test +import de.bixilon.minosoft.protocol.packets.factory.PacketTypeRegistry +import org.testng.annotations.Test -internal class VersionsSIT { - @Test - @Order(2) +internal class MinosoftSIT { + + @Test(priority = 0) + fun disableGC() { + Thread { + val reference = Minosoft + reference.hashCode() + while (true) { + Thread.sleep(100L) + } + }.start() + } + + @Test(priority = 1) + fun initAssetsManager() { + Minosoft.MINOSOFT_ASSETS_MANAGER.load(CountUpAndDownLatch(0)) + } + + @Test(priority = 2) + fun setupPacketRegistry() { + PacketTypeRegistry.init(CountUpAndDownLatch(0)) + } + + @Test(priority = 3) fun loadVersionsJson() { Versions.load(CountUpAndDownLatch(0)) } diff --git a/src/integreation-test/kotlin/de/bixilon/minosoft/test/data/registries/versions/VersionsIT.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/VersionsIT.kt similarity index 84% rename from src/integreation-test/kotlin/de/bixilon/minosoft/test/data/registries/versions/VersionsIT.kt rename to src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/VersionsIT.kt index 0118d8356..6bdab1247 100644 --- a/src/integreation-test/kotlin/de/bixilon/minosoft/test/data/registries/versions/VersionsIT.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/VersionsIT.kt @@ -11,12 +11,11 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.test.data.registries.versions +package de.bixilon.minosoft.data.registries.versions -import de.bixilon.minosoft.data.registries.versions.Versions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals +import org.testng.Assert.assertEquals +import org.testng.annotations.Test internal class VersionsIT { diff --git a/src/integreation-test/kotlin/de/bixilon/minosoft/setup/MinosoftSIT.kt b/src/integreation-test/kotlin/de/bixilon/minosoft/setup/MinosoftSIT.kt deleted file mode 100644 index 246f0b5bd..000000000 --- a/src/integreation-test/kotlin/de/bixilon/minosoft/setup/MinosoftSIT.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.setup - -import de.bixilon.kutil.latch.CountUpAndDownLatch -import de.bixilon.minosoft.Minosoft -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Order -import org.junit.jupiter.api.Test - -internal class MinosoftSIT { - - @Test - @Order(1) - fun initAssetsManager() { - Minosoft.MINOSOFT_ASSETS_MANAGER.load(CountUpAndDownLatch(0)) - print("Initialized assets manager") - } -} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/factory/PacketTypeRegistry.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/factory/PacketTypeRegistry.kt index c30723f71..878ce6cfb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/factory/PacketTypeRegistry.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/factory/PacketTypeRegistry.kt @@ -91,7 +91,7 @@ object PacketTypeRegistry { val innerLatch = CountUpAndDownLatch(1, latch) for (info in ClassPath.from(classLoader).getTopLevelClassesRecursive(PacketsRoot::class.java.packageName)) { innerLatch.inc() - DefaultThreadPool += { loadClass(s2cClassMap, s2cStateMap, c2sClassMap, c2sStateMap, info);innerLatch.dec() } + DefaultThreadPool += { loadClass(s2cClassMap, s2cStateMap, c2sClassMap, c2sStateMap, info); innerLatch.dec() } } innerLatch.dec() innerLatch.await()