vy commented on code in PR #3934:
URL: https://github.com/apache/logging-log4j2/pull/3934#discussion_r2402495546


##########
log4j-core-test/pom.xml:
##########
@@ -347,6 +347,12 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-inline</artifactId>
+      <scope>test</scope>
+    </dependency>
+

Review Comment:
   You're right, it was an oversight from my side. Formatting should take place 
as long as there're active threads tampering the suppressed exception array. 
The following should do the trick:
   
   ```diff
   Index: 
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
   IDEA additional info:
   Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
   <+>UTF-8
   ===================================================================
   diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
   --- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
 (revision 0ba25694d606f4ff483ae2b8717d5773b6f99dbc)
   +++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
 (date 1759507533630)
   @@ -29,6 +29,7 @@
    import java.util.concurrent.CountDownLatch;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
   +import java.util.concurrent.atomic.AtomicInteger;
    import java.util.concurrent.locks.LockSupport;
    import java.util.stream.Collectors;
    import java.util.stream.IntStream;
   @@ -453,6 +454,7 @@
                final CountDownLatch startLatch =
                        new CountDownLatch(threadCount + /* the main thread 
invoking the rendering: */ 1);
                final int exceptionPerThreadCount = 100;
   +            final AtomicInteger runningThreadCountRef = new 
AtomicInteger(threadCount);
    
                // Schedule threads that will start adding suppressed 
exceptions with the start signal
                for (int threadIndex = 0; threadIndex < threadCount; 
threadIndex++) {
   @@ -472,6 +474,8 @@
                        } catch (InterruptedException ignored) {
                            // Restore the interrupt
                            Thread.currentThread().interrupt();
   +                    } finally {
   +                        runningThreadCountRef.decrementAndGet();
                        }
                    });
                }
   @@ -491,7 +495,7 @@
                // Trigger the start latch and format the exception
                startLatch.countDown();
                startLatch.await();
   -            for (int i = 0; i < 1_000_000; i++) {
   +            while (runningThreadCountRef.get() > 0) {
                    // Give some time slack to increase randomness
                    LockSupport.parkNanos(1);
                    patternFormatter.format(logEvent, buffer);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to