Skip to content

Commit

Permalink
Do not send empty test suite spans
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Jun 15, 2023
1 parent 27b4c27 commit 46afe94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void setSkipReason(String skipReason) {

@Override
public void end(@Nullable Long endTime) {
span.setTag(Tags.TEST_STATUS, context.getStatus());
String status = context.getStatus();
span.setTag(Tags.TEST_STATUS, status != null ? status : CIConstants.TEST_SKIP);
testDecorator.beforeFinish(span);

if (endTime != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import datadog.trace.api.civisibility.CIConstants;
import datadog.trace.api.civisibility.DDTest;
import datadog.trace.api.civisibility.DDTestSuite;
import datadog.trace.api.civisibility.decorator.TestDecorator;
import datadog.trace.api.civisibility.source.SourcePathResolver;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
Expand All @@ -17,6 +16,7 @@
import datadog.trace.civisibility.codeowners.Codeowners;
import datadog.trace.civisibility.context.SpanTestContext;
import datadog.trace.civisibility.context.TestContext;
import datadog.trace.civisibility.decorator.TestDecorator;
import datadog.trace.civisibility.source.MethodLinesResolver;
import java.lang.reflect.Method;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -143,13 +143,16 @@ public void end(@Nullable Long endTime) {
testDecorator.beforeFinish(span);

String status = context.getStatus();
span.setTag(Tags.TEST_STATUS, status);
moduleContext.reportChildStatus(status);

if (endTime != null) {
span.finish(endTime);
} else {
span.finish();
if (status != null) {
// do not report test suite if no execution took place
span.setTag(Tags.TEST_STATUS, status);
moduleContext.reportChildStatus(status);

if (endTime != null) {
span.finish(endTime);
} else {
span.finish();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@

abstract class AbstractTestContext implements TestContext {

private String status = CIConstants.TEST_SKIP;
private String status;

@Override
public synchronized void reportChildStatus(String childStatus) {
switch (childStatus) {
case CIConstants.TEST_PASS:
if (CIConstants.TEST_SKIP.equals(status)) {
if (status == null || CIConstants.TEST_SKIP.equals(status)) {
status = CIConstants.TEST_PASS;
}
break;
case CIConstants.TEST_FAIL:
status = CIConstants.TEST_FAIL;
break;
case CIConstants.TEST_SKIP:
if (status == null) {
status = CIConstants.TEST_SKIP;
}
break;
default:
break;
}
Expand Down

0 comments on commit 46afe94

Please sign in to comment.