add tests

This commit is contained in:
nkzawa
2016-02-01 01:50:09 +09:00
parent 48420a6c6f
commit ba723d0460
3 changed files with 71 additions and 6 deletions

View File

@@ -7,10 +7,13 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.net.URISyntaxException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;
@@ -61,6 +64,33 @@ public class SocketTest extends Connection {
assertThat(id.isPresent(), is(false));
}
@Test(timeout = TIMEOUT)
public void doesNotFireConnectErrorIfWeForceDisconnectInOpeningState() throws URISyntaxException, InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
IO.Options opts = new IO.Options();
opts.timeout = 100;
socket = client(opts);
socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
values.offer(Optional.of(new Error("Unexpected")));
}
});
socket.connect();
socket.disconnect();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
values.offer(Optional.empty());
}
}, 300);
@SuppressWarnings("unchecked")
Optional<Error> err = values.take();
if (err.isPresent()) throw err.get();
}
@Test(timeout = TIMEOUT)
public void pingAndPongWithLatency() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();