Skip to content

Commit

Permalink
Enable test to handle different TCP reset behaviours on different ope…
Browse files Browse the repository at this point in the history
…rating systems

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1719446 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Dec 11, 2015
1 parent 8ec8c07 commit d63bab5
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions test/org/apache/tomcat/websocket/server/TestClose.java
Expand Up @@ -17,6 +17,8 @@
package org.apache.tomcat.websocket.server;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -90,10 +92,19 @@ private static void awaitLatch(CountDownLatch latch, String failMessage) {
}


public static void awaitOnClose(CloseCode code) {
public static void awaitOnClose(CloseCode... codes) {
Set<CloseCode> set = new HashSet<>();
for (CloseCode code : codes) {
set.add(code);
}
awaitOnClose(set);
}


public static void awaitOnClose(Set<CloseCode> codes) {
awaitLatch(events.onCloseCalled, "onClose not called");
Assert.assertEquals(code.getCode(), events.closeReason.getCloseCode()
.getCode());
CloseCode received = events.closeReason.getCloseCode();
Assert.assertTrue("Rx: " + received, codes.contains(received));
}


Expand Down Expand Up @@ -159,8 +170,14 @@ public void testWsCloseThenTcpReset() throws Exception {
client.sendCloseFrame(CloseCodes.GOING_AWAY);
client.forceCloseSocket();

// WebSocket 1.1, section 2.1.5 requires this to be CLOSED_ABNORMALLY
awaitOnClose(CloseCodes.CLOSED_ABNORMALLY);
// WebSocket 1.1, section 2.1.5 requires this to be CLOSED_ABNORMALLY if
// the container initiates the close and the close close from the client
// if the client initiates it. When the client resets the TCP connection
// after sending the close, different operating systems react different
// ways. Some present the close message then drop the connection, some
// just drop the connection. Therefore, this test has to handle both
// close codes.
awaitOnClose(CloseCodes.CLOSED_ABNORMALLY, CloseCodes.GOING_AWAY);
}


Expand Down

0 comments on commit d63bab5

Please sign in to comment.