Skip to content

Commit f24b784

Browse files
committed
Adding a test for connecting invalidated/connected transports.
1 parent 4aa2fd1 commit f24b784

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

tests/io/socket/AbstractTestSocketIO.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void setUp() throws Exception {
9898
node = Runtime.getRuntime().exec(
9999
new String[] { NODE, "./tests/io/socket/testutils/socketio.js",
100100
"" + getPort(), transport });
101-
proxy = new MutateProxy(getPort()+1, getPort());
101+
proxy = new MutateProxy(getPort() + 1, getPort());
102102
proxy.start();
103103

104104
stdoutThread = new Thread("stdoutThread") {
@@ -190,7 +190,8 @@ public void tearDown() throws Exception {
190190
*/
191191
void doConnect() throws Exception {
192192
// Setting up socket connection
193-
socket = new SocketIO("http://127.0.0.1:" + getProxyPort() + "/main", this);
193+
socket = new SocketIO("http://127.0.0.1:" + getProxyPort() + "/main",
194+
this);
194195
assertEquals("onConnect", takeEvent());
195196
assertEquals(transport, socket.getTransport());
196197
}
@@ -245,12 +246,12 @@ public void emitAndOn() throws Exception {
245246

246247
socket.emit("echo");
247248
assertEquals("Test String", "on", takeEvent());
248-
249+
249250
String str = "TESTSTRING";
250251
socket.emit("echo", str);
251252
assertEquals("Test String", "on", takeEvent());
252253
assertEquals(str, takeArg());
253-
254+
254255
JSONObject obj = new JSONObject("{'foo':'bar'}");
255256
socket.emit("echo", obj);
256257
assertEquals("Test JSON", "on", takeEvent());
@@ -291,16 +292,16 @@ public void emitAndMessage() throws Exception {
291292
*/
292293
@Test(timeout = TIMEOUT)
293294
public void namespaces() throws Exception {
294-
SocketIO ns1 = new SocketIO("http://127.0.0.1:" + getProxyPort() + "/ns1",
295-
this);
295+
SocketIO ns1 = new SocketIO("http://127.0.0.1:" + getProxyPort()
296+
+ "/ns1", this);
296297
assertEquals("onConnect", takeEvent());
297298

298299
doConnect();
299300
ns1.disconnect();
300301
assertEquals("onDisconnect", takeEvent());
301302

302-
SocketIO ns2 = new SocketIO("http://127.0.0.1:" + getProxyPort() + "/ns2",
303-
this);
303+
SocketIO ns2 = new SocketIO("http://127.0.0.1:" + getProxyPort()
304+
+ "/ns2", this);
304305
assertEquals("onConnect", takeEvent());
305306
assertEquals("onMessage_string", takeEvent());
306307
assertEquals("ns2", takeArg());
@@ -311,8 +312,8 @@ public void namespaces() throws Exception {
311312
assertEquals("onMessage_string", takeEvent());
312313
assertEquals("TESTSTRING", takeArg());
313314

314-
SocketIO ns2_2 = new SocketIO("http://127.0.0.1:" + getProxyPort() + "/ns2",
315-
this);
315+
SocketIO ns2_2 = new SocketIO("http://127.0.0.1:" + getProxyPort()
316+
+ "/ns2", this);
316317
assertEquals("onConnect", takeEvent());
317318

318319
assertEquals("onMessage_string", takeEvent());
@@ -357,14 +358,25 @@ public void ack(Object... args) {
357358
}, "TESTSTRING");
358359
assertEquals("ack", takeEvent());
359360
assertEquals("TESTSTRING", takeArg());
360-
361+
361362
socket.emit(REQUEST_ACKNOWLEDGE, "TESTSTRING");
362363
assertEquals("on", takeEvent());
363-
assertEquals("TESTSTRING", takeArg());
364+
assertEquals("TESTSTRING", takeArg());
364365
assertEquals("ACKNOWLEDGE:TESTSTRING", takeLine());
365366
doClose();
366367
}
367368

369+
@Test(timeout = TIMEOUT)
370+
public void reconnectInvalidated() throws Exception {
371+
doConnect();
372+
socket.disconnect();
373+
try {
374+
socket.connect(this);
375+
fail("reconnecting an invalidated socket should fail");
376+
} catch (RuntimeException ex) {
377+
}
378+
}
379+
368380
// END TESTS
369381

370382
/**
@@ -470,7 +482,7 @@ public void onMessage(JSONObject json, IOAcknowledge ack) {
470482
@Override
471483
public void on(String event, IOAcknowledge ack, Object... args) {
472484
events.add("on");
473-
if(event.equals(REQUEST_ACKNOWLEDGE)) {
485+
if (event.equals(REQUEST_ACKNOWLEDGE)) {
474486
ack.ack(args);
475487
}
476488
this.args.addAll(Arrays.asList(args));
@@ -497,7 +509,7 @@ public int getPort() {
497509
port = 2048 + (int) (Math.random() * 10000) * 2;
498510
return port;
499511
}
500-
512+
501513
public int getProxyPort() {
502514
return getPort() + (proxy == null ? 0 : 1);
503515
}

0 commit comments

Comments
 (0)