Repository navigation
Support test automation exclusions in TestNG #12942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
calvinbayer
wants to merge
7
commits into
codex/junit5-automation-exclusions
Choose a base branch
from
codex/testng-automation-exclusions
base: codex/junit5-automation-exclusions
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a128fe1
Apply automation exclusions and preserve explicit TestNG retries
calvinbayer 32f540b
Handle missing TestNG version metadata when preserving native retries
calvinbayer a3bf944
Preserve TestNG native retry analyzer resolution and construction
calvinbayer 4f95e9c
Use effective TestNG groups for exclusion skip decisions
calvinbayer ae9acf2
Load TestNG object factory fixtures with an explicit classloader
calvinbayer 9c86fe3
Include TestNG exclusion policy dependencies in explicit helper lists
calvinbayer e434620
Preserve explicitly disabled retries in TestNG transformers
calvinbayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ommon/src/main/java/datadog/trace/instrumentation/testng/TestNGMethodInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package datadog.trace.instrumentation.testng; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import datadog.trace.agent.tooling.Instrumenter; | ||
| import datadog.trace.agent.tooling.InstrumenterModule; | ||
| import datadog.trace.api.Config; | ||
| import net.bytebuddy.asm.Advice; | ||
| import org.testng.ITestNGMethod; | ||
| import org.testng.internal.annotations.IAnnotationFinder; | ||
|
|
||
| @AutoService(InstrumenterModule.class) | ||
| public class TestNGMethodInstrumentation extends InstrumenterModule.CiVisibility | ||
| implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { | ||
| public TestNGMethodInstrumentation() { | ||
| super("testng", "test-retry"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEnabled() { | ||
| return super.isEnabled() && Config.get().isCiVisibilityExecutionPoliciesEnabled(); | ||
| } | ||
|
|
||
| @Override | ||
| public String instrumentedType() { | ||
| return "org.testng.internal.TestNGMethod"; | ||
| } | ||
|
|
||
| @Override | ||
| public void methodAdvice(MethodTransformer transformer) { | ||
| transformer.applyAdvice(isConstructor(), getClass().getName() + "$ConfigureRetryAdvice"); | ||
| } | ||
|
|
||
| public static class ConfigureRetryAdvice { | ||
| @Advice.OnMethodExit | ||
| public static void configure( | ||
| @Advice.This ITestNGMethod method, | ||
| @Advice.FieldValue("m_annotationFinder") IAnnotationFinder annotationFinder) { | ||
| TestNGUtils.configureRetryAnalyzer(method, annotationFinder); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../main/java/datadog/trace/instrumentation/testng/execution/RetryAnnotationTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,64 @@ | ||
| package datadog.trace.instrumentation.testng.execution; | ||
|
|
||
| import datadog.trace.util.MethodHandles; | ||
| import java.lang.invoke.MethodHandle; | ||
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.Method; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.WeakHashMap; | ||
| import org.testng.IAnnotationTransformer; | ||
| import org.testng.IRetryAnalyzer; | ||
| import org.testng.TestNG; | ||
| import org.testng.annotations.ITestAnnotation; | ||
|
|
||
| public class RetryAnnotationTransformer implements IAnnotationTransformer { | ||
| private static final MethodHandles METHOD_HANDLES = | ||
| new MethodHandles(TestNG.class.getClassLoader()); | ||
| private static final MethodHandle GET_RETRY_ANALYZER_CLASS = | ||
| METHOD_HANDLES.method(ITestAnnotation.class, "getRetryAnalyzerClass"); | ||
| private static final MethodHandle GET_RETRY_ANALYZER = | ||
| METHOD_HANDLES.method(ITestAnnotation.class, "getRetryAnalyzer"); | ||
| private static final Map<ITestAnnotation, Boolean> FRAMEWORK_OVERRIDES = | ||
| Collections.synchronizedMap(new WeakHashMap<ITestAnnotation, Boolean>()); | ||
| private final IAnnotationTransformer delegate; | ||
|
|
||
| public RetryAnnotationTransformer(IAnnotationTransformer delegate) { | ||
| this.delegate = delegate; | ||
| } | ||
|
|
||
| public static boolean hasFrameworkOverride(ITestAnnotation annotation) { | ||
| if (annotation == null) { | ||
| return false; | ||
| } | ||
| Boolean overridden = FRAMEWORK_OVERRIDES.get(annotation); | ||
| // A user-installed transformer can replace ours after TestNG construction. | ||
| return overridden == null || overridden; | ||
| } | ||
|
|
||
| private static Class<?> retryAnalyzerClass(ITestAnnotation annotation) { | ||
| if (GET_RETRY_ANALYZER_CLASS != null) { | ||
| return METHOD_HANDLES.invoke(GET_RETRY_ANALYZER_CLASS, annotation); | ||
| } | ||
| IRetryAnalyzer analyzer = METHOD_HANDLES.invoke(GET_RETRY_ANALYZER, annotation); | ||
| return analyzer != null ? analyzer.getClass() : null; | ||
| } | ||
|
|
||
| @Override | ||
| public void transform( | ||
| ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { | ||
| FRAMEWORK_OVERRIDES.put(annotation, false); | ||
| Class<?> nativeAnalyzer = retryAnalyzerClass(annotation); | ||
| annotation.setRetryAnalyzer(RetryAnalyzer.class); | ||
| if (delegate != null) { | ||
| delegate.transform(annotation, testClass, testConstructor, testMethod); | ||
| } | ||
| if (retryAnalyzerClass(annotation) != RetryAnalyzer.class) { | ||
| // Preserve the existing precedence of explicit user transformer overrides. | ||
| FRAMEWORK_OVERRIDES.put(annotation, true); | ||
| } else if (nativeAnalyzer != null) { | ||
| // Let TestNG resolve class inheritance and effective groups before selecting DD policy. | ||
| annotation.setRetryAnalyzer(nativeAnalyzer); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a quarantined @NoAutoRetry test with a native retry analyzer and parallel data-provider invocations, distinct parameter objects with identical toString() values produce the same TestIdentifier and share this tracker. Both workers can set its suppressFailures flag before either consumes it; getAndResetSuppressFailures() then clears it for one worker, leaving the other's quarantined failure blocking the build. Isolate suppression state per ITestResult, updating both RetryAnalyzer and the execution advice.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
🤖 Bits Code Review · Open Bits AI session