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

namelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e6363638ad IGNITE-16838 Fixed flaky 
TcpCommunicationSpiFreezingClientTest#testFreezingClient test (#9986)
3e6363638ad is described below

commit 3e6363638ad4249a5cb06f27a8ba7f9f5b6b5c75
Author: Nikita Amelchev <nsamelc...@gmail.com>
AuthorDate: Wed Apr 20 12:15:59 2022 +0300

    IGNITE-16838 Fixed flaky 
TcpCommunicationSpiFreezingClientTest#testFreezingClient test (#9986)
    
    Co-authored-by: Pavel Pereslegin <xxt...@gmail.com>
---
 .../ignite/internal/util/GridJavaProcess.java      | 14 ++++
 .../tcp/TcpCommunicationSpiFreezingClientTest.java | 84 ++++------------------
 2 files changed, 29 insertions(+), 69 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
index 7beb865618b..30312e6f835 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
@@ -251,6 +251,20 @@ public final class GridJavaProcess {
         return proc;
     }
 
+    /** Suspends the process. */
+    public void suspend() throws Exception {
+        if (!U.isUnix() && !U.isMacOs())
+            throw new UnsupportedOperationException();
+
+        if (pid.equals(DFLT_PID))
+            return;
+
+        Process stopProc = Runtime.getRuntime().exec(new String[]{"kill", 
"-STOP", pid});
+
+        if (!stopProc.waitFor(5000, TimeUnit.MILLISECONDS))
+            throw new IllegalStateException("The stop process is hanging.");
+    }
+
     /**
      * Class which grabs sys.err and sys.out of the running process in 
separate thread
      * and implements the interchange-with-a-process protocol.
diff --git 
a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFreezingClientTest.java
 
b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFreezingClientTest.java
index c81a7016a5f..aa601df2d12 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFreezingClientTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiFreezingClientTest.java
@@ -19,21 +19,17 @@ package org.apache.ignite.spi.communication.tcp;
 
 import java.util.Map;
 import java.util.UUID;
-import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCompute;
-import org.apache.ignite.Ignition;
 import org.apache.ignite.cluster.ClusterTopologyException;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.util.nio.GridCommunicationClient;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.ListeningTestLogger;
-import org.apache.ignite.testframework.junits.GridAbstractTest;
 import org.apache.ignite.testframework.junits.WithSystemProperty;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy;
+import org.junit.Assume;
 import org.junit.Test;
 
 import static 
org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_FORCIBLE_NODE_KILL;
@@ -44,12 +40,6 @@ import static 
org.apache.ignite.testframework.GridTestUtils.waitForCondition;
  */
 @WithSystemProperty(key = IGNITE_ENABLE_FORCIBLE_NODE_KILL, value = "true")
 public class TcpCommunicationSpiFreezingClientTest extends 
GridCommonAbstractTest {
-    /** Message to catch GC start on a client. */
-    private static final String GC_START_MSG = "Try to start GC.";
-
-    /** Last GC start time. */
-    private final AtomicLong lastGC = new AtomicLong(Long.MAX_VALUE);
-
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -66,15 +56,6 @@ public class TcpCommunicationSpiFreezingClientTest extends 
GridCommonAbstractTes
 
         cfg.setCommunicationSpi(spi);
 
-        ListeningTestLogger log = new 
ListeningTestLogger(GridAbstractTest.log);
-
-        log.registerListener((s) -> {
-            if (s.contains(GC_START_MSG))
-                lastGC.set(System.currentTimeMillis());
-        });
-
-        cfg.setGridLogger(log);
-
         return cfg;
     }
 
@@ -85,60 +66,25 @@ public class TcpCommunicationSpiFreezingClientTest extends 
GridCommonAbstractTes
 
     /** @throws Exception If failed. */
     @Test
+    @SuppressWarnings("ThrowableNotThrown")
     public void testFreezingClient() throws Exception {
-        Ignite srv = startGrid(0);
-        Ignite client = startClientGrid("client");
-        IgniteCompute compute = 
srv.compute(srv.cluster().forNode(client.cluster().localNode())).withNoFailover();
-
-        // Close communication connections by idle and trigger STW on the 
client.
-        compute.runAsync(() -> {
-            waitConnectionsClosed(Ignition.localIgnite());
-
-            triggerSTW();
-        });
-
-        while (!Thread.interrupted()) {
-            // Make sure connections closed on the server.
-            waitConnectionsClosed(srv);
-
-            // Make sure that the client is freezed by STW.
-            assertTrue(waitForCondition(() -> System.currentTimeMillis() - 
lastGC.get() > 1000, getTestTimeout()));
-
-            // Open new connection to the freezed client. Retry if client has 
completed GC and was not freezed.
-            try {
-                compute.run(() -> {});
-            }
-            catch (ClusterTopologyException ignored) {
-                break;
-            }
-        }
-
-        assertEquals(1, srv.cluster().nodes().size());
-    }
-
-    /** Triggers STW. */
-    private void triggerSTW() {
-        long end = System.currentTimeMillis() + getTestTimeout();
-
-        while (!Thread.interrupted() && (System.currentTimeMillis() < end)) {
-            IgniteInternalFuture<?> fut = 
GridTestUtils.runAsync(this::simulateLoad);
+        Assume.assumeTrue("The test reqires the 'kill' command.", U.isUnix() 
|| U.isMacOs());
 
-            while (!fut.isDone()) {
-                System.out.println(GC_START_MSG);
+        Ignite srv = startGrid(0);
+        IgniteProcessProxy client = 
(IgniteProcessProxy)startClientGrid("client");
 
-                GridTestUtils.runGC();
-            }
-        }
-    }
+        // Close communication connections by idle.
+        waitConnectionsClosed(srv);
 
-    /** Simulate load without safepoints to block GC. */
-    public double simulateLoad() {
-        double d = 0;
+        // Simulate freeze/STW on the client.
+        client.getProcess().suspend();
 
-        for (int i = 0; i < Integer.MAX_VALUE; i++)
-            d += Math.log(Math.PI * i);
+        // Open new communication connection to the freezing client.
+        GridTestUtils.assertThrowsWithCause(
+            () -> 
srv.compute(srv.cluster().forClients()).withNoFailover().run(() -> {}),
+            ClusterTopologyException.class);
 
-        return d;
+        assertEquals(1, srv.cluster().nodes().size());
     }
 
     /** Waits for all communication connections closed by idle. */

Reply via email to