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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new e2b2d90b6 fix: when running testThreadGroups and testThreadGroupsById 
in two threads, they have the same thread group name, will cause test failed. 
(#1051)
e2b2d90b6 is described below

commit e2b2d90b60b93bd4c4a1e3bcda6557f1d8917c0f
Author: 徐梦旗 <2663479...@qq.com>
AuthorDate: Fri Apr 14 08:07:14 2023 +0800

    fix: when running testThreadGroups and testThreadGroupsById in two threads, 
they have the same thread group name, will cause test failed. (#1051)
---
 .../org/apache/commons/lang3/ThreadUtilsTest.java    | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java
index ac4d72a15..89e135cf3 100644
--- a/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java
@@ -225,7 +225,8 @@ public class ThreadUtilsTest extends AbstractLangTest {
 
     @Test
     public void testThreadGroups() throws InterruptedException {
-        final ThreadGroup threadGroup = new 
ThreadGroup("thread_group_DDZZ99__");
+        final String threadGroupName = 
"thread_group_DDZZ99__for_testThreadGroups";
+        final ThreadGroup threadGroup = new ThreadGroup(threadGroupName);
         final Thread t1 = new TestThread(threadGroup, "thread1_XXOOPP__");
         final Thread t2 = new TestThread(threadGroup, "thread2_XXOOPP__");
 
@@ -233,11 +234,11 @@ public class ThreadUtilsTest extends AbstractLangTest {
             t1.start();
             t2.start();
             assertEquals(1, 
ThreadUtils.findThreadsByName("thread1_XXOOPP__").size());
-            assertEquals(1, ThreadUtils.findThreadsByName("thread1_XXOOPP__", 
"thread_group_DDZZ99__").size());
-            assertEquals(1, ThreadUtils.findThreadsByName("thread2_XXOOPP__", 
"thread_group_DDZZ99__").size());
+            assertEquals(1, ThreadUtils.findThreadsByName("thread1_XXOOPP__", 
threadGroupName).size());
+            assertEquals(1, ThreadUtils.findThreadsByName("thread2_XXOOPP__", 
threadGroupName).size());
             assertEquals(0, ThreadUtils.findThreadsByName("thread1_XXOOPP__", 
"non_existent_thread_group_JJHHZZ__").size());
-            assertEquals(0, 
ThreadUtils.findThreadsByName("non_existent_thread_BBDDWW__", 
"thread_group_DDZZ99__").size());
-            assertEquals(1, 
ThreadUtils.findThreadGroupsByName("thread_group_DDZZ99__").size());
+            assertEquals(0, 
ThreadUtils.findThreadsByName("non_existent_thread_BBDDWW__", 
threadGroupName).size());
+            assertEquals(1, 
ThreadUtils.findThreadGroupsByName(threadGroupName).size());
             assertEquals(0, 
ThreadUtils.findThreadGroupsByName("non_existent_thread_group_JJHHZZ__").size());
             assertNotNull(ThreadUtils.findThreadById(t1.getId(), threadGroup));
         } finally {
@@ -251,7 +252,8 @@ public class ThreadUtilsTest extends AbstractLangTest {
 
     @Test
     public void testThreadGroupsById() throws InterruptedException {
-        final ThreadGroup threadGroup = new 
ThreadGroup("thread_group_DDZZ99__");
+        final String threadGroupName = 
"thread_group_DDZZ99__for_testThreadGroupsById";
+        final ThreadGroup threadGroup = new ThreadGroup(threadGroupName);
         final Thread t1 = new TestThread(threadGroup, "thread1_XXOOPP__");
         final Thread t2 = new TestThread(threadGroup, "thread2_XXOOPP__");
         final long nonExistingId = t1.getId() + t2.getId();
@@ -259,10 +261,10 @@ public class ThreadUtilsTest extends AbstractLangTest {
         try {
             t1.start();
             t2.start();
-            assertSame(t1, ThreadUtils.findThreadById(t1.getId(), 
"thread_group_DDZZ99__"));
-            assertSame(t2, ThreadUtils.findThreadById(t2.getId(), 
"thread_group_DDZZ99__"));
+            assertSame(t1, ThreadUtils.findThreadById(t1.getId(), 
threadGroupName));
+            assertSame(t2, ThreadUtils.findThreadById(t2.getId(), 
threadGroupName));
             assertNull(ThreadUtils.findThreadById(nonExistingId, 
"non_existent_thread_group_JJHHZZ__"));
-            assertNull(ThreadUtils.findThreadById(nonExistingId, 
"thread_group_DDZZ99__"));
+            assertNull(ThreadUtils.findThreadById(nonExistingId, 
threadGroupName));
         } finally {
             t1.interrupt();
             t2.interrupt();

Reply via email to