Commit e4f2ab40 authored by Benedikt Geißler's avatar Benedikt Geißler 🐸

Enhance "reliability" of the ClientLoginTest

(unfortunately the test still fails rarely)
parent 710e5e73
......@@ -23,6 +23,7 @@ dependencies {
compile 'org.json:json:20160810'
compile 'org.everit.json:org.everit.json.schema:1.+'
testCompile 'junit:junit:4.+'
testCompile 'org.awaitility:awaitility:2.+'
}
checkstyle {
......
package gone.lib.network.test;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Awaitility.fieldIn;
import static org.junit.Assert.assertTrue;
import gone.lib.common.ClientRole;
import gone.lib.network.contracts.ITcpListener;
import gone.lib.network.json.CwLoginContent;
......@@ -8,9 +13,10 @@ import gone.lib.network.serialization.IncomingMessagesInterpreter;
import gone.lib.network.serialization.OutgoingMessagesSerializer;
import gone.lib.network.tcp.TcpClientModule;
import gone.lib.network.tcp.TcpServerModule;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.Callable;
/**
* Created by winfr on 26.09.2016.
*/
......@@ -26,35 +32,29 @@ public class ClientLoginTest {
receivedLogin = interpreter.getMessageType(data) == CwMessageType.Login;
}
public boolean receivedLogin;
boolean receivedLogin;
}
@Test
public void testSingleClientLogin() throws InterruptedException {
TcpServerModule server = new TcpServerModule();
ServerListener listener = new ServerListener();
server.registerListener(listener);
server.start(5556);
TcpClientModule client = new TcpClientModule();
client.connect("localhost", 5556);
OutgoingMessagesSerializer serializer = new OutgoingMessagesSerializer();
CwLoginContent content = new CwLoginContent();
content.name = "testWarrior";
content.role = ClientRole.Player;
Thread.sleep(100);
client.sendMessage(serializer.serializeLoginMessage(content));
Thread.sleep(100);
Callable<Boolean> hasReceivedLogin = fieldIn(listener).ofType(boolean.class).andWithName("receivedLogin");
await().atMost(1, SECONDS).until(hasReceivedLogin);
server.stop();
client.disconnect();
Assert.assertTrue(listener.receivedLogin);
assertTrue(listener.receivedLogin);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment