GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Make WebSocketHandshakeHandOverTest.testClientHandshak… · netty/netty@71d479d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src/test/java/io/netty/handler/codec/http/websocketx
    • WebSocketHandshakeHandOverTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ public void testHandshakeFutureIsNotifiedOnChannelClose() throws Exception {
235235
@Test
236236
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
237237
public void testClientHandshakerForceClose() throws Exception {
238+
final long forceCloseTimeoutMillis = 10000;
238239
final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
239240
new URI("ws://localhost:1234/test"), WebSocketVersion.V13, null, true,
240-
EmptyHttpHeaders.INSTANCE, Integer.MAX_VALUE, true, false, 20);
241+
EmptyHttpHeaders.INSTANCE, Integer.MAX_VALUE, true, false, forceCloseTimeoutMillis);
241242

242243
EmbeddedChannel serverChannel = createServerChannel(
243244
new CloseNoOpServerProtocolHandler("/test"),
@@ -260,6 +261,10 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except
260261
}
261262
});
262263

264+
// Freeze the clock of the client so the force close timeout can only fire when we advance the time
265+
// explicitly. Otherwise a slow machine could make the timeout expire before we check that it has not.
266+
clientChannel.freezeTime();
267+
263268
// Transfer the handshake from the client to the server
264269
transferAllDataWithMerge(clientChannel, serverChannel);
265270
// Transfer the handshake from the server to client
@@ -271,11 +276,15 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except
271276
// Should not be closed yet as we disabled closing the connection on the server
272277
assertFalse(clientForceClosed);
273278

274-
while (!clientForceClosed) {
275-
Thread.sleep(10);
276-
// We need to run all pending tasks as the force close timeout is scheduled on the EventLoop.
277-
clientChannel.runPendingTasks();
278-
}
279+
// Just before the timeout the connection must still be open.
280+
clientChannel.advanceTimeBy(forceCloseTimeoutMillis - 1, TimeUnit.MILLISECONDS);
281+
clientChannel.runScheduledPendingTasks();
282+
assertFalse(clientForceClosed);
283+
284+
// The force close timeout is scheduled on the EventLoop, so advance the time to trigger it.
285+
clientChannel.advanceTimeBy(1, TimeUnit.MILLISECONDS);
286+
clientChannel.runScheduledPendingTasks();
287+
assertTrue(clientForceClosed);
279288

280289
// clientForceClosed would be set to TRUE after any close,
281290
// so check here that force close timeout was actually fired

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.