Skip to content

Commit

Permalink
fix: improving test logic for TestStreamSendsErrorCode to avoid flaki…
Browse files Browse the repository at this point in the history
…ness (#3049)
  • Loading branch information
darccio authored Dec 19, 2024
1 parent 2dfcb2a commit 76d4896
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions contrib/google.golang.org/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,20 +520,20 @@ func TestStreamSendsErrorCode(t *testing.T) {
// to flush the spans
_, _ = stream.Recv()

containsErrorCode := false
spans := mt.FinishedSpans()

// check if at least one span has error code
// check if at least one span with spank.kind=server has error code
var span mocktracer.Span
for _, s := range spans {
if s.Tag(tagCode) == wantCode {
containsErrorCode = true
if s.Tag(tagCode) != wantCode {
continue
}
if s.Tag(ext.SpanKind) != ext.SpanKindServer {
continue
}
span = s
}
assert.True(t, containsErrorCode, "at least one span should contain error code, the spans were:\n%v", spans)

// ensure that last span contains error code also
gotLastSpanCode := spans[len(spans)-1].Tag(tagCode)
assert.Equal(t, wantCode, gotLastSpanCode, "last span should contain error code")
assert.NotNilf(t, span, "at least one span should contain error code, the spans were:\n%v", spans)
}

// fixtureServer a dummy implementation of our grpc fixtureServer.
Expand Down

0 comments on commit 76d4896

Please sign in to comment.