-
Notifications
You must be signed in to change notification settings - Fork 312
Align retry logic for all test framework instrumentations #8803
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
Changes from all commits
b5ca4e8
72fa990
64034a7
f8cff99
ad337c0
a5087e1
bfbc0f1
5f76e24
21f3ac7
97e4285
3268b48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package datadog.trace.civisibility.execution; | ||
|
||
import datadog.trace.api.civisibility.execution.TestExecutionPolicy; | ||
import datadog.trace.api.civisibility.execution.TestStatus; | ||
import datadog.trace.api.civisibility.telemetry.tag.RetryReason; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import javax.annotation.Nullable; | ||
|
@@ -13,42 +14,47 @@ public class RetryUntilSuccessful implements TestExecutionPolicy { | |
private int executions; | ||
private boolean successfulExecutionSeen; | ||
|
||
/** Total execution counter that is shared by all retry policies */ | ||
private final AtomicInteger totalExecutions; | ||
/** Total retry counter that is shared by all retry until successful policies (currently ATR) */ | ||
private final AtomicInteger totalRetryCount; | ||
|
||
public RetryUntilSuccessful( | ||
int maxExecutions, boolean suppressFailures, AtomicInteger totalExecutions) { | ||
int maxExecutions, boolean suppressFailures, AtomicInteger totalRetryCount) { | ||
this.maxExecutions = maxExecutions; | ||
this.suppressFailures = suppressFailures; | ||
this.totalExecutions = totalExecutions; | ||
this.totalRetryCount = totalRetryCount; | ||
this.executions = 0; | ||
} | ||
|
||
@Override | ||
public boolean applicable() { | ||
return !currentExecutionIsLast() || suppressFailures; | ||
public void registerExecution(TestStatus status, long durationMillis) { | ||
++executions; | ||
successfulExecutionSeen |= (status != TestStatus.fail); | ||
if (executions > 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we not count the first execution here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I'd say let's rename |
||
totalRetryCount.incrementAndGet(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean suppressFailures() { | ||
// do not suppress failures for last execution | ||
// (unless flag to suppress all failures is set) | ||
return !currentExecutionIsLast() || suppressFailures; | ||
public boolean wasLastExecution() { | ||
return successfulExecutionSeen || executions == maxExecutions; | ||
} | ||
|
||
private boolean currentExecutionIsLast() { | ||
return executions == maxExecutions - 1; | ||
} | ||
|
||
@Override | ||
public boolean retry(boolean successful, long durationMillis) { | ||
successfulExecutionSeen |= successful; | ||
if (!successful && ++executions < maxExecutions) { | ||
totalExecutions.incrementAndGet(); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
public boolean applicable() { | ||
// executions must always be registered, therefore consider it applicable as long as there are | ||
// retries left | ||
return !wasLastExecution(); | ||
} | ||
|
||
@Override | ||
public boolean suppressFailures() { | ||
// do not suppress failures for last execution | ||
// (unless flag to suppress all failures is set) | ||
return !currentExecutionIsLast() || suppressFailures; | ||
} | ||
|
||
@Nullable | ||
|
@@ -63,7 +69,7 @@ private boolean currentExecutionIsRetry() { | |
|
||
@Override | ||
public boolean hasFailedAllRetries() { | ||
return currentExecutionIsLast() && !successfulExecutionSeen; | ||
return wasLastExecution() && !successfulExecutionSeen; | ||
} | ||
|
||
@Override | ||
|
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.
Unused import?
Uh oh!
There was an error while loading. Please reload this page.
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.
The line change is due to a refactor. I moved the
TestStatus
class to the API package to use it inTestExecutionHistory
, previously it was only internal