Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for server to start in WorldBuilder.createServer #4367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
import net.minecraft.util.Util;

import net.fabricmc.fabric.api.client.gametest.v1.ClientGameTestContext;

public final class DedicatedServerImplUtil {
private static final Logger LOGGER = LoggerFactory.getLogger("fabric-client-gametest-api-v1");
private static final Properties DEFAULT_SERVER_PROPERTIES = Util.make(new Properties(), properties -> {
Expand All @@ -59,19 +61,24 @@ public final class DedicatedServerImplUtil {
private DedicatedServerImplUtil() {
}

public static MinecraftDedicatedServer start(Properties serverProperties) {
public static MinecraftDedicatedServer start(ClientGameTestContext context, Properties serverProperties) {
setupServer(serverProperties);
serverFuture = new CompletableFuture<>();

new Thread(() -> Main.main(new String[0])).start();

MinecraftDedicatedServer server;

try {
return serverFuture.get(10, TimeUnit.SECONDS);
server = serverFuture.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
} finally {
serverFuture = null;
}

context.waitFor(client -> ThreadingImpl.isServerRunning && ThreadingImpl.serverCanAcceptTasks);
return server;
}

private static void setupServer(Properties customServerProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public TestDedicatedServerContext createServer(Properties serverProperties) {
DedicatedServerImplUtil.saveLevelDataTo = null;
}

MinecraftDedicatedServer server = DedicatedServerImplUtil.start(serverProperties);
MinecraftDedicatedServer server = DedicatedServerImplUtil.start(context, serverProperties);
return new TestDedicatedServerContextImpl(context, server);
}

Expand Down