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

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


The following commit(s) were added to refs/heads/master by this push:
     new c23ff05  Fix flaky SlingStatusPrinterTest by sampling msgSince before 
adding the status
c23ff05 is described below

commit c23ff05afd4e6151aad2670ad35ce0da5fe930f2
Author: Roy Teeuwen <[email protected]>
AuthorDate: Mon Jun 15 21:54:32 2026 +0200

    Fix flaky SlingStatusPrinterTest by sampling msgSince before adding the 
status
    
    The status timestamp could be earlier than msgSince when a millisecond 
boundary
    fell between adding the WarnStatus and reading System.currentTimeMillis(), 
causing
    filterStatusListByTimeThreshold to drop the status and the assertion to fail
    intermittently.
---
 .../commons/log/logback/internal/util/SlingStatusPrinterTest.java     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/src/test/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinterTest.java
 
b/src/test/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinterTest.java
index c774f23..256e61b 100644
--- 
a/src/test/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinterTest.java
+++ 
b/src/test/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinterTest.java
@@ -80,9 +80,11 @@ class SlingStatusPrinterTest {
     @ValueSource(booleans = {true, false})
     void testPrintInCaseOfErrorsOrWarningsWithApplicableStatus(boolean 
initSuccess) throws Exception {
         LoggerContext context = (LoggerContext) 
LoggerFactory.getILoggerFactory();
-        context.getStatusManager().add(new WarnStatus("Something went wrong", 
context));
         long threshold = Long.MIN_VALUE;
+        // Sample msgSince before adding the status so the status timestamp is 
always >= msgSince.
+        // Sampling it afterwards lets a millisecond tick between the two 
calls filter the status out (flaky).
         long msgSince = System.currentTimeMillis();
+        context.getStatusManager().add(new WarnStatus("Something went wrong", 
context));
         try (LogCapture capture = new 
LogCapture(SlingStatusPrinter.class.getName(), true)) {
             TestUtils.doWorkWithCapturedStdOut(
                     () -> 
SlingStatusPrinter.printInCaseOfErrorsOrWarnings(context, threshold, msgSince, 
initSuccess));

Reply via email to