mirror of https://github.com/grpc/grpc-go.git
Fixed the test cases
This commit is contained in:
parent
3720f4e30e
commit
b97a2da403
|
@ -20,8 +20,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"reflect"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -285,10 +287,27 @@ func validateTraces(t *testing.T, spans tracetest.SpanStubs, wantSpanInfos []tra
|
||||||
key := traceSpanInfoMapKey{spanName: info.name, spanKind: info.spanKind}
|
key := traceSpanInfoMapKey{spanName: info.name, spanKind: info.spanKind}
|
||||||
wantSpanInfosMap[key] = info
|
wantSpanInfosMap[key] = info
|
||||||
}
|
}
|
||||||
|
used := make([]bool, len(wantSpanInfos))
|
||||||
// Compare retrieved spans with expected spans.
|
// Compare retrieved spans with expected spans.
|
||||||
for i, span := range spans {
|
for _, span := range spans {
|
||||||
want := wantSpanInfos[i]
|
var matchedIndex = -1
|
||||||
|
for i, want := range wantSpanInfos {
|
||||||
|
if used[i] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if want.name == span.Name && want.spanKind == span.SpanKind.String() {
|
||||||
|
matchedIndex = i
|
||||||
|
used[i] = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if matchedIndex == -1 {
|
||||||
|
t.Errorf("Unexpected span: %q (%s)", span.Name, span.SpanKind)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
want := wantSpanInfos[matchedIndex]
|
||||||
// Check that the attempt span has the correct status.
|
// Check that the attempt span has the correct status.
|
||||||
if want.status != otelcodes.Unset {
|
if want.status != otelcodes.Unset {
|
||||||
got, want := span.Status.Code, want.status
|
got, want := span.Status.Code, want.status
|
||||||
|
@ -306,7 +325,13 @@ func validateTraces(t *testing.T, spans tracetest.SpanStubs, wantSpanInfos []tra
|
||||||
return a.Key < b.Key
|
return a.Key < b.Key
|
||||||
})
|
})
|
||||||
attributesValueComparable := cmpopts.EquateComparable(attribute.KeyValue{}.Value)
|
attributesValueComparable := cmpopts.EquateComparable(attribute.KeyValue{}.Value)
|
||||||
eventsTimeIgnore := cmpopts.IgnoreFields(trace.Event{}, "Time")
|
eventsTimeIgnore := cmp.FilterPath(
|
||||||
|
func(p cmp.Path) bool {
|
||||||
|
return p.Last().Type() == reflect.TypeOf(time.Time{}) &&
|
||||||
|
strings.HasSuffix(p.GoString(), ".Time")
|
||||||
|
},
|
||||||
|
cmp.Ignore(),
|
||||||
|
)
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
if diff := cmp.Diff(want.attributes, span.Attributes, attributesSort, attributesValueComparable); diff != "" {
|
if diff := cmp.Diff(want.attributes, span.Attributes, attributesSort, attributesValueComparable); diff != "" {
|
||||||
|
@ -1506,8 +1531,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
setupStub func() *stubserver.StubServer
|
setupStub func() *stubserver.StubServer
|
||||||
doCall func(context.Context, testgrpc.TestServiceClient) error
|
doCall func(context.Context, testgrpc.TestServiceClient) error
|
||||||
spanName string
|
wantSpanInfosFn func() []traceSpanInfo
|
||||||
wantSpanInfosFn func(spanName string) []traceSpanInfo
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "unary",
|
name: "unary",
|
||||||
|
@ -1530,8 +1554,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) {
|
||||||
_, err := client.UnaryCall(ctx, &testpb.SimpleRequest{})
|
_, err := client.UnaryCall(ctx, &testpb.SimpleRequest{})
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
spanName: "Sent.grpc.testing.TestService.UnaryCall",
|
wantSpanInfosFn: func() []traceSpanInfo {
|
||||||
wantSpanInfosFn: func(spanName string) []traceSpanInfo {
|
|
||||||
return []traceSpanInfo{
|
return []traceSpanInfo{
|
||||||
{
|
{
|
||||||
name: "Recv.grpc.testing.TestService.UnaryCall",
|
name: "Recv.grpc.testing.TestService.UnaryCall",
|
||||||
|
@ -1719,8 +1742,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
spanName: "Sent.grpc.testing.TestService.FullDuplexCall",
|
wantSpanInfosFn: func() []traceSpanInfo {
|
||||||
wantSpanInfosFn: func(spanName string) []traceSpanInfo {
|
|
||||||
return []traceSpanInfo{
|
return []traceSpanInfo{
|
||||||
{
|
{
|
||||||
name: "Recv.grpc.testing.TestService.FullDuplexCall",
|
name: "Recv.grpc.testing.TestService.FullDuplexCall",
|
||||||
|
@ -1890,7 +1912,7 @@ func (s) TestTraceSpan_WithRetriesAndNameResolutionDelay(t *testing.T) {
|
||||||
t.Fatalf("%s call failed: %v", tt.name, err)
|
t.Fatalf("%s call failed: %v", tt.name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wantSpanInfos := tt.wantSpanInfosFn(tt.spanName)
|
wantSpanInfos := tt.wantSpanInfosFn()
|
||||||
spans, err := waitForTraceSpans(ctx, exporter, wantSpanInfos)
|
spans, err := waitForTraceSpans(ctx, exporter, wantSpanInfos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue