Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why are the changes needed?
I observe the following failure when running this test (ch.qos.logback.classic.blackbox.net.SMTPAppender_GreenTest.testCustomEvaluator) due to the slow execution of logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java#L682. When SMTPAppenderBase.java#682 is not executed quick enough, the test method (testCustomEvaluator) tries to execute the assertion given at Line#156, but it then fails. While it may be possible to fix this flaky test by increasing the waiting time in the test-code, but I believe such a fix might be unstable in a CI environment or when run on different machines, given the dependency on some constant wait time. Hence, I suggest a new way to fix the test by adding some synchronization for the test execution only. I at first identify the code location that needs to be executed before the test should proceed to check assertions (logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java#682). so I introduce one variable in this test class that is only there to provide some synchronization. Basically, until this statement is executed, I force the thread that the test runs to wait before it proceeds to the assertions.
Why are the changes needed?
ch.qos.logback.classic.blackbox.net.SMTPAppender_GreenTest.testCustomEvaluator Time elapsed: 6.163 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <1> but was: <0>
at org.junit.jupiter.api@5.9.1/org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at org.junit.jupiter.api@5.9.1/org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at org.junit.jupiter.api@5.9.1/org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
at org.junit.jupiter.api@5.9.1/org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
at org.junit.jupiter.api@5.9.1/org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145)
at org.junit.jupiter.api@5.9.1/org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:528)
at logback.classic.blackbox/ch.qos.logback.classic.blackbox.net.SMTPAppender_GreenTest.verifyAndExtractMimeMultipart(SMTPAppender_GreenTest.java:157)
at logback.classic.blackbox/ch.qos.logback.classic.blackbox.net.SMTPAppender_GreenTest.testCustomEvaluator(SMTPAppender_GreenTest.java:316)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.engine@1.9.1/org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine@1.9.1/org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine@1.9.1/org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine@1.9.1/org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
How was this patch tested?
I run this test more than 1000 times and the test always passes.