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

tkalkirill 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 f96adc857c0 IGNITE-28449 Fix flaky 
IgniteThreadGroupNodeRestartTest#testNodeRestartInsideThreadGroup (#12977)
f96adc857c0 is described below

commit f96adc857c0c43171055114f2fe7adbd63b83571
Author: Kirill Tkalenko <[email protected]>
AuthorDate: Fri Apr 3 15:16:39 2026 +0300

    IGNITE-28449 Fix flaky 
IgniteThreadGroupNodeRestartTest#testNodeRestartInsideThreadGroup (#12977)
    
    https://issues.apache.org/jira/browse/IGNITE-28449
---
 .../internal/IgniteThreadGroupNodeRestartTest.java | 74 ++++++++++++++++++++--
 1 file changed, 68 insertions(+), 6 deletions(-)

diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/IgniteThreadGroupNodeRestartTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/IgniteThreadGroupNodeRestartTest.java
index a828b9a49b1..e2ad00f6556 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/IgniteThreadGroupNodeRestartTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/IgniteThreadGroupNodeRestartTest.java
@@ -17,14 +17,33 @@
 
 package org.apache.ignite.internal;
 
+import java.util.Arrays;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Test;
 
+import static java.util.stream.Collectors.joining;
+
 /**
  *
  */
 public class IgniteThreadGroupNodeRestartTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
     /**
      * @throws Exception if failed.
      */
@@ -36,9 +55,7 @@ public class IgniteThreadGroupNodeRestartTest extends 
GridCommonAbstractTest {
 
         Thread t = new Thread(tg, () -> {
             try {
-                startGrid(0);
-
-                stopGrid(0);
+                startStopGrid(0);
             }
             catch (Exception e) {
                 err.set(e);
@@ -47,13 +64,58 @@ public class IgniteThreadGroupNodeRestartTest extends 
GridCommonAbstractTest {
 
         t.start();
         t.join(getTestTimeout());
+        assertFalse(t.isAlive());
 
         if (err.get() != null)
             throw err.get();
 
-        tg.destroy();
+        destroyWithWaitAllThreadIsComplete(tg, getTestTimeout());
+
+        startStopGrid(0);
+    }
+
+    /** */
+    private void startStopGrid(int idx) throws Exception {
+        startGrid(idx);
+        stopGrid(idx);
+    }
+
+    /** */
+    private static void destroyWithWaitAllThreadIsComplete(ThreadGroup tg, 
long millis) throws Exception {
+        if (GridTestUtils.waitForCondition(() -> tg.activeCount() == 0, 
millis, 10) || tg.activeCount() == 0) {
+            tg.destroy();
+
+            return;
+        }
+
+        Thread[] threads = new Thread[tg.activeCount() + 256];
+        int copied = tg.enumerate(threads, true);
+
+        if (copied == 0) {
+            tg.destroy();
+
+            return;
+        }
+
+        fail(String.format(
+            "Thread group still has active threads: [count=%s, threads=%s]",
+            copied, threadInfos(threads)
+        ));
+    }
+
+    /** */
+    private static String threadInfos(Thread... threads) {
+        return Arrays.stream(threads)
+            .filter(Objects::nonNull)
+            .map(IgniteThreadGroupNodeRestartTest::threadInfo)
+            .collect(joining(", ", "[", "]"));
+    }
 
-        startGrid(0);
-        stopGrid(0);
+    /** */
+    private static String threadInfo(Thread t) {
+        return String.format(
+            "[id=%s, name=%s, alive=%s, deamon=%s, state=%s]",
+            t.getId(), t.getName(), t.isAlive(), t.isDaemon(), t.getState()
+        );
     }
 }

Reply via email to