This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-agent-test-tool.git


The following commit(s) were added to refs/heads/master by this push:
     new e7b4efe  Enhance the segment span validation (#53)
e7b4efe is described below

commit e7b4efe0a51ca1b55d966a181887e1e6cf9fb672
Author: mrproliu <[email protected]>
AuthorDate: Thu Jul 20 13:07:52 2023 +0800

    Enhance the segment span validation (#53)
---
 .../tool/validator/assertor/SegmentAssert.java     | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java
 
b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java
index ee6dbbb..1c29805 100644
--- 
a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java
+++ 
b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java
@@ -20,6 +20,7 @@ package 
org.apache.skywalking.plugin.test.agent.tool.validator.assertor;
 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;
@@ -90,7 +91,28 @@ public class SegmentAssert {
             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);
+                }
             }
         }
 

Reply via email to