Skip to content

Commit

Permalink
Enhance the segment span validation (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu committed Jul 20, 2023
1 parent 17a37cc commit e7b4efe
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ActualSegmentRefIsEmptyException;
import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.KeyValueNotEqualsException;
Expand Down Expand Up @@ -90,7 +91,28 @@ private static boolean spansEquals(List<Span> excepted, List<Span> actual) {
try {
spanEquals(exceptedSpan, actualSpan);
} catch (AssertFailedException e) {
throw new SpanAssertFailedException(e, exceptedSpan, actualSpan);
if (Objects.equals(exceptedSpan.spanId(), actualSpan.spanId())) {
throw new SpanAssertFailedException(e, exceptedSpan, actualSpan);
}
// if the span id is not equals, trying to find the span by span id
Span tmpSpan = null;
for (Span s : actual) {
if (Objects.equals(exceptedSpan.spanId(), s.spanId())) {
tmpSpan = s;
break;
}
}
if (tmpSpan == null) {
// keep the original exception if the span not found
throw new SpanAssertFailedException(e, exceptedSpan, actualSpan);
}
actualSpan = tmpSpan;
// if the span still not equals, throw the exception
try {
spanEquals(exceptedSpan, actualSpan);
} catch (AssertFailedException e1) {
throw new SpanAssertFailedException(e1, exceptedSpan, actualSpan);
}
}
}

Expand Down

0 comments on commit e7b4efe

Please sign in to comment.