From 0f9c2322ce8ba6b7acafb36bb62e67962554c200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=8F=AF?= Date: Thu, 1 Aug 2024 18:13:09 +0800 Subject: [PATCH] ci: fix trace test case --- dataloader_test.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/dataloader_test.go b/dataloader_test.go index 779c8aa..8c8f26d 100644 --- a/dataloader_test.go +++ b/dataloader_test.go @@ -62,20 +62,31 @@ func testTrace(t *testing.T) { t.Errorf("Expected 11 spans, got %d", len(spans.Snapshots())) } - if spans.Snapshots()[0].Name() != "dataLoader.Batch" { - t.Errorf("Unexpected span name: %v", spans.Snapshots()[0].Name()) - } - - if len(spans.Snapshots()[0].Links()) != 10 { - t.Errorf("Expected 10 links, got %d", len(spans.Snapshots()[0].Links())) + haveBatch := false + haveLoad := false + loadCount := 0 + for _, s := range spans.Snapshots() { + if s.Name() == "dataLoader.Batch" { + haveBatch = true + if len(s.Links()) != 10 { + t.Errorf("Expected 10 links, got %d", len(s.Links())) + } + } + if s.Name() == "dataLoader.Load" { + loadCount++ + haveLoad = true + if len(s.Links()) != 0 { + t.Errorf("Expected 0 link, got %d", len(s.Links())) + } + } } - if spans.Snapshots()[1].Name() != "dataLoader.Load" { - t.Errorf("Unexpected span name: %v", spans.Snapshots()[0].Name()) + if !haveBatch { + t.Errorf("Expected to have a batch span") } - if len(spans.Snapshots()[1].Links()) != 0 { - t.Errorf("Expected 3 links, got %d", len(spans.Snapshots()[0].Links())) + if !haveLoad { + t.Errorf("Expected to have a load span") } exporter.Reset()