Skip to content

Commit

Permalink
Include a unique system ID so the tests don't interfere with each other
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 15, 2024
1 parent 7b86414 commit 32f285b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static ScreenChain createHost() {
.skip(LevelLoadingScreen.class, ReceivingLevelScreen.class)
.then(null, () -> press(InputConstants.KEY_ESCAPE))
.then(PauseScreen.class, () -> click(findWidgetByTranslation("world-host.online_status")))
.then(addFriend("o:JOINER"))
.then(addFriend(TestingUser.JOINER))
.then(PauseScreen.class, () -> click(findWidgetByTranslation("world-host.open_world")))
.then(ShareToLanScreen.class, () -> click(findWidgetByTranslation("world-host.open_world")))
.then(null, () -> waitForJoinerToJoin(0))
Expand All @@ -75,7 +75,7 @@ private static void waitForJoinerToJoin(long timeSpent) {
private static ScreenChain createJoiner() {
return ScreenChain.start()
.then(TitleScreen.class, () -> click(findWidgetByTranslation("world-host.online_status")))
.then(addFriend("o:HOST"))
.then(addFriend(TestingUser.HOST))
.then(TitleScreen.class, () -> click(findWidgetByTranslation("menu.multiplayer")))
.maybe(SafetyScreen.class, () -> click(findWidgetByTranslation("gui.proceed")))
.then(JoinMultiplayerScreen.class, () -> click(findWidgetByTranslation("world-host.friends")))
Expand Down Expand Up @@ -117,18 +117,26 @@ private static void waitForHostToHost(long timeSpent) {
}
}

private static ScreenChain addFriend(String user) {
private static ScreenChain addFriend(TestingUser user) {
return ScreenChain.start()
.then(WorldHostConfigScreen.class, () -> click(findWidgetByTranslation("world-host.friends")))
.then(FriendsScreen.class, () -> click(findWidgetByTranslation("world-host.add_friend")))
.then(AddFriendScreen.class, () -> {
enterText(findWidgetByTranslation("world-host.add_friend.enter_username"), user);
enterText(findWidgetByTranslation("world-host.add_friend.enter_username"), "o:" + user + getUsernameSuffix());
click(findWidgetByTranslation("world-host.add_friend"));
})
.then(FriendsScreen.class, () -> click(findWidgetByTranslation("gui.done")))
.then(WorldHostConfigScreen.class, () -> click(findWidgetByTranslation("gui.done")));
}

private static String getUsernameSuffix() {
final String username = Minecraft.getInstance().getUser().getName();
if (!username.startsWith(USER.name())) {
throw new IllegalStateException("Username " + username + " doesn't start with " + USER);
}
return username.substring(USER.name().length());
}

public enum TestingUser {
HOST, JOINER
}
Expand Down
5 changes: 4 additions & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.replaymod.gradle.preprocess.PreprocessTask
import groovy.lang.GroovyObjectSupport
import org.jetbrains.kotlin.daemon.common.toHexString
import xyz.wagyourtail.unimined.api.mapping.task.ExportMappingsTask
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import xyz.wagyourtail.unimined.internal.mapping.MappingsProvider
Expand All @@ -8,6 +9,7 @@ import xyz.wagyourtail.unimined.internal.minecraft.patch.AbstractMinecraftTransf
import xyz.wagyourtail.unimined.internal.minecraft.resolver.MinecraftDownloader
import xyz.wagyourtail.unimined.util.capitalized
import xyz.wagyourtail.unimined.util.sourceSets
import java.net.NetworkInterface
import java.nio.file.Path

plugins {
Expand Down Expand Up @@ -150,10 +152,11 @@ unimined.minecraft {
for (name in listOf("host", "joiner")) {
val runName = "test${name.capitalized()}"
val user = name.uppercase()
val uniqueSystemId = NetworkInterface.getNetworkInterfaces().iterator().next().hardwareAddress.toHexString()
val provider = (minecraftData as MinecraftDownloader).provider
val baseConfig = provider.provideVanillaRunClientTask(runName, file("run/$runName"))
baseConfig.description = "Test $user"
baseConfig.args.replaceAll { if (it == "Dev") user else it }
baseConfig.args.replaceAll { if (it == "Dev") "$user$uniqueSystemId" else it }
baseConfig.jvmArgs.add("-Dworld-host-testing.enabled=true")
baseConfig.jvmArgs.add("-Dworld-host-testing.user=$user")
baseConfig.jvmArgs.add("-Ddevauth.enabled=false")
Expand Down

0 comments on commit 32f285b

Please sign in to comment.