You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2021/08/03 16:56:23 UTC

[ignite-3] branch main updated: IGNITE-15237 Thin 3.0: Fix ClientHandlerIntegrationTest flakiness (#255)

This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new fe2334b  IGNITE-15237 Thin 3.0: Fix ClientHandlerIntegrationTest flakiness (#255)
fe2334b is described below

commit fe2334bf54b7b10800feb8fff4ba77b23fb30406
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Tue Aug 3 19:55:25 2021 +0300

    IGNITE-15237 Thin 3.0: Fix ClientHandlerIntegrationTest flakiness (#255)
    
    Connect to the actual server port, do not assume 10800: server can bind to any port from the range.
---
 .../ignite/client/handler/ClientHandlerIntegrationTest.java   | 11 ++++++++---
 .../java/org/apache/ignite/client/AbstractClientTest.java     | 10 ++++++----
 .../test/java/org/apache/ignite/client/ConnectionTest.java    |  8 ++++----
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/modules/client-handler/src/test/java/org/apache/ignite/client/handler/ClientHandlerIntegrationTest.java b/modules/client-handler/src/test/java/org/apache/ignite/client/handler/ClientHandlerIntegrationTest.java
index 67a8454..6304b8a 100644
--- a/modules/client-handler/src/test/java/org/apache/ignite/client/handler/ClientHandlerIntegrationTest.java
+++ b/modules/client-handler/src/test/java/org/apache/ignite/client/handler/ClientHandlerIntegrationTest.java
@@ -19,6 +19,7 @@ package org.apache.ignite.client.handler;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.util.Collections;
 import io.netty.channel.ChannelFuture;
@@ -48,21 +49,25 @@ public class ClientHandlerIntegrationTest {
 
     private ConfigurationRegistry configurationRegistry;
 
+    private int serverPort;
+
     @BeforeEach
     public void setUp() throws Exception {
         serverFuture = startServer();
+        serverPort = ((InetSocketAddress)serverFuture.channel().localAddress()).getPort();
     }
 
     @AfterEach
     public void tearDown() throws Exception {
         serverFuture.cancel(true);
         serverFuture.await();
+        serverFuture.channel().closeFuture().await();
         configurationRegistry.stop();
     }
 
     @Test
     void testHandshakeInvalidMagicHeaderDropsConnection() throws Exception {
-        try (var sock = new Socket("127.0.0.1", 10800)) {
+        try (var sock = new Socket("127.0.0.1", serverPort)) {
             OutputStream out = sock.getOutputStream();
             out.write(new byte[]{63, 64, 65, 66, 67});
             out.flush();
@@ -73,7 +78,7 @@ public class ClientHandlerIntegrationTest {
 
     @Test
     void testHandshakeValidReturnsSuccess() throws Exception {
-        try (var sock = new Socket("127.0.0.1", 10800)) {
+        try (var sock = new Socket("127.0.0.1", serverPort)) {
             OutputStream out = sock.getOutputStream();
 
             // Magic: IGNI
@@ -125,7 +130,7 @@ public class ClientHandlerIntegrationTest {
 
     @Test
     void testHandshakeInvalidVersionReturnsError() throws Exception {
-        try (var sock = new Socket("127.0.0.1", 10800)) {
+        try (var sock = new Socket("127.0.0.1", serverPort)) {
             OutputStream out = sock.getOutputStream();
 
             // Magic: IGNI
diff --git a/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java b/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
index dbaf32c..48678a9 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
@@ -51,11 +51,15 @@ public abstract class AbstractClientTest {
 
     protected static Ignite client;
 
+    protected static int serverPort;
+
     @BeforeAll
     public static void beforeAll() throws Exception {
         ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
 
         serverFuture = startServer(null);
+        serverPort = ((InetSocketAddress)serverFuture.channel().localAddress()).getPort();
+
         client = startClient();
     }
 
@@ -64,6 +68,7 @@ public abstract class AbstractClientTest {
         client.close();
         serverFuture.cancel(true);
         serverFuture.await();
+        serverFuture.channel().closeFuture().await();
         configurationRegistry.stop();
     }
 
@@ -74,11 +79,8 @@ public abstract class AbstractClientTest {
     }
 
     public static Ignite startClient(String... addrs) {
-        if (addrs == null || addrs.length == 0) {
-            var serverPort = ((InetSocketAddress)serverFuture.channel().localAddress()).getPort();
-
+        if (addrs == null || addrs.length == 0)
             addrs = new String[]{"127.0.0.2:" + serverPort};
-        }
 
         var builder = IgniteClient.builder().addresses(addrs);
 
diff --git a/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java b/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java
index 3c0e34c..3bfab34 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/ConnectionTest.java
@@ -42,11 +42,11 @@ public class ConnectionTest extends AbstractClientTest {
 
     @Test
     public void testValidNodeAddresses() throws Exception {
-        testConnection("127.0.0.1:10800");
+        testConnection("127.0.0.1:" + serverPort);
     }
 
     @Test
-    public void testInvalidNodeAddresses() throws Exception {
+    public void testInvalidNodeAddresses() {
         var ex = assertThrows(IgniteClientConnectionException.class,
                 () -> testConnection("127.0.0.1:47500"));
 
@@ -55,13 +55,13 @@ public class ConnectionTest extends AbstractClientTest {
 
     @Test
     public void testValidInvalidNodeAddressesMix() throws Exception {
-        testConnection("127.0.0.1:47500", "127.0.0.1:10801", "127.0.0.1:10800");
+        testConnection("127.0.0.1:47500", "127.0.0.1:10801", "127.0.0.1:" + serverPort);
     }
 
     @Disabled("IPv6 is not enabled by default on some systems.")
     @Test
     public void testIPv6NodeAddresses() throws Exception {
-        testConnection("[::1]:10800");
+        testConnection("[::1]:" + serverPort);
     }
 
     private void testConnection(String... addrs) throws Exception {