From c05849826752d3693265e32cb49fed008f29baa3 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Mon, 7 Oct 2013 05:16:20 +0200 Subject: [PATCH] Add a timeout to server startup and the ping test. --- .../protocol/SimpleCraftBukkitITCase.java | 12 +++++++++++- .../integration/protocol/TestPingPacket.java | 10 ++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ProtocolLib/src/test/java/com/comphenix/integration/protocol/SimpleCraftBukkitITCase.java b/ProtocolLib/src/test/java/com/comphenix/integration/protocol/SimpleCraftBukkitITCase.java index 07e57a01..05a8e4e3 100644 --- a/ProtocolLib/src/test/java/com/comphenix/integration/protocol/SimpleCraftBukkitITCase.java +++ b/ProtocolLib/src/test/java/com/comphenix/integration/protocol/SimpleCraftBukkitITCase.java @@ -7,6 +7,8 @@ import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; + import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -29,6 +31,14 @@ public class SimpleCraftBukkitITCase { // The fake plugin private static volatile Plugin FAKE_PLUGIN = null; + /** + * The maximum amount of time to wait before a server has started. + *

+ * We have to give it the ample time of 60 seconds, as a server may have to + * generate the spawn area in three worlds. + */ + private static final int TIMEOUT_MS = 60000; + /** * Setup the CraftBukkit server for all the tests. * @throws IOException Unable to setup server. @@ -55,7 +65,7 @@ public class SimpleCraftBukkitITCase { public Object call() throws Exception { return null; } - }).get(); + }).get(TIMEOUT_MS, TimeUnit.MILLISECONDS); // Plugins are now ready } diff --git a/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java b/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java index c5f90d22..1ab03022 100644 --- a/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java +++ b/ProtocolLib/src/test/java/com/comphenix/integration/protocol/TestPingPacket.java @@ -6,6 +6,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.bukkit.plugin.Plugin; @@ -22,6 +23,9 @@ public class TestPingPacket { private static final String CRAFTBUKKIT_VERSION = "1.6.2"; private static final int PROTOCOL_VERSION = 74; + // Timeout + private static final int TIMEOUT_PING_MS = 10000; + private volatile String source; private TestPingPacket() { @@ -43,7 +47,8 @@ public class TestPingPacket { */ public void startTest(Plugin plugin) throws Throwable { try { - String transmitted = testInterception(plugin).get(); + String transmitted = testInterception(plugin). + get(TIMEOUT_PING_MS, TimeUnit.MILLISECONDS); // Make sure it's the same System.out.println("Server string: " + transmitted); @@ -66,7 +71,8 @@ public class TestPingPacket { return Executors.newSingleThreadExecutor().submit(new Callable() { @Override public String call() throws Exception { - SimpleMinecraftClient client = new SimpleMinecraftClient(new MinecraftVersion(CRAFTBUKKIT_VERSION), PROTOCOL_VERSION); + SimpleMinecraftClient client = new SimpleMinecraftClient( + new MinecraftVersion(CRAFTBUKKIT_VERSION), PROTOCOL_VERSION); String information = client.queryLocalPing(); // Wait for the listener to catch up