GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Avoid leak presence detector in leak profile (#17073) · netty/netty@9f403a8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pom.xml
  • testsuite-common/src
    • main/java/io/netty/util/test
      • LeakPresenceExtension.java
    • test/java/io/netty/util/test
      • LeakPresenceExtensionTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pom.xml‎

Copy file name to clipboardExpand all lines: pom.xml
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@
620620
<profile>
621621
<id>leak</id>
622622
<properties>
623-
<argLine.leak>-Dio.netty.leakDetectionLevel=paranoid -Dio.netty.leakDetection.targetRecords=32</argLine.leak>
623+
<argLine.leak>
624+
-Dio.netty.leakDetectionLevel=paranoid
625+
-Dio.netty.leakDetection.targetRecords=32
626+
-Dio.netty.test.leakPresenceDetection.disabled=true
627+
</argLine.leak>
624628
</properties>
625629
</profile>
626630
<profile>
Collapse file

‎testsuite-common/src/main/java/io/netty/util/test/LeakPresenceExtension.java‎

Copy file name to clipboardExpand all lines: testsuite-common/src/main/java/io/netty/util/test/LeakPresenceExtension.java
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.junit.jupiter.api.extension.AfterEachCallback;
2222
import org.junit.jupiter.api.extension.BeforeAllCallback;
2323
import org.junit.jupiter.api.extension.BeforeEachCallback;
24+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
2425
import org.junit.jupiter.api.extension.ExtensionContext;
26+
import org.junit.jupiter.api.extension.ExecutionCondition;
2527

2628
import java.util.Objects;
2729
import java.util.concurrent.TimeUnit;
@@ -44,13 +46,27 @@
4446
* in a test are assigned to the test resource scope.
4547
*/
4648
public final class LeakPresenceExtension
47-
implements BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback {
49+
implements ExecutionCondition, BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback {
50+
51+
static final String LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY =
52+
"io.netty.test.leakPresenceDetection.disabled";
4853

4954
private static final Object SCOPE_KEY = new Object();
5055
private static final Object PREVIOUS_SCOPE_KEY = new Object();
5156

5257
static {
53-
System.setProperty("io.netty.customResourceLeakDetector", WithTransferableScope.class.getName());
58+
if (!Boolean.getBoolean(LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY)) {
59+
System.setProperty("io.netty.customResourceLeakDetector", WithTransferableScope.class.getName());
60+
}
61+
}
62+
63+
@Override
64+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
65+
if (Boolean.getBoolean(LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY)) {
66+
return ConditionEvaluationResult.disabled(
67+
"Leak presence detection disabled by " + LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY);
68+
}
69+
return ConditionEvaluationResult.enabled("Leak presence detection enabled");
5470
}
5571

5672
@Override
Collapse file

‎testsuite-common/src/test/java/io/netty/util/test/LeakPresenceExtensionTest.java‎

Copy file name to clipboardExpand all lines: testsuite-common/src/test/java/io/netty/util/test/LeakPresenceExtensionTest.java
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.junit.jupiter.api.Nested;
1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.extension.ExtendWith;
2021
import org.junit.platform.testkit.engine.EngineExecutionResults;
2122
import org.junit.platform.testkit.engine.EngineTestKit;
2223

@@ -35,6 +36,27 @@ void nestedClassLifecycleIsSupported() {
3536
results.testEvents().succeeded().assertThatEvents().hasSize(2);
3637
}
3738

39+
@Test
40+
void explicitExtensionTestIsSkippedWhenLeakPresenceDetectionIsDisabled() {
41+
String previous = System.getProperty(LeakPresenceExtension.LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY);
42+
System.setProperty(LeakPresenceExtension.LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY, "true");
43+
try {
44+
EngineExecutionResults results = EngineTestKit.engine("junit-jupiter")
45+
.selectors(selectClass(ExplicitExtensionTest.class))
46+
.execute();
47+
48+
results.containerEvents().failed().assertThatEvents().isEmpty();
49+
results.containerEvents().skipped().assertThatEvents().hasSize(1);
50+
results.testEvents().succeeded().assertThatEvents().isEmpty();
51+
} finally {
52+
if (previous == null) {
53+
System.clearProperty(LeakPresenceExtension.LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY);
54+
} else {
55+
System.setProperty(LeakPresenceExtension.LEAK_PRESENCE_DETECTION_DISABLED_PROPERTY, previous);
56+
}
57+
}
58+
}
59+
3860
@Test
3961
void inheritedTestClassExecutesParentAndChildTests() {
4062
EngineExecutionResults results = EngineTestKit.engine("junit-jupiter")
@@ -70,4 +92,11 @@ static class InheritedChildTest extends InheritedParentTest {
7092
void childTest() {
7193
}
7294
}
95+
96+
@ExtendWith(LeakPresenceExtension.class)
97+
static class ExplicitExtensionTest {
98+
@Test
99+
void test() {
100+
}
101+
}
73102
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.