From 23122db3f9d4595812b90307c9daf39f387d683d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 7 Nov 2023 09:43:09 +0100 Subject: [PATCH 1/2] otelgrpc: Stablize TestInterceptors --- .../grpc/otelgrpc/test/grpc_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index 6d8a82676ba..6a9a48ab130 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -19,6 +19,7 @@ import ( "net" "strconv" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -132,19 +133,31 @@ func TestInterceptors(t *testing.T) { require.NoError(t, err) t.Run("UnaryClientSpans", func(t *testing.T) { + require.EventuallyWithT(t, func(c *assert.CollectT) { + assert.Len(c, clientUnarySR.Ended(), 2) + }, 5*time.Second, 100*time.Millisecond) checkUnaryClientSpans(t, clientUnarySR.Ended(), listener.Addr().String()) }) t.Run("StreamClientSpans", func(t *testing.T) { + require.EventuallyWithT(t, func(c *assert.CollectT) { + assert.Len(c, clientStreamSR.Ended(), 3) + }, 5*time.Second, 100*time.Millisecond) checkStreamClientSpans(t, clientStreamSR.Ended(), listener.Addr().String()) }) t.Run("UnaryServerSpans", func(t *testing.T) { + require.EventuallyWithT(t, func(c *assert.CollectT) { + assert.Len(c, serverUnarySR.Ended(), 2) + }, 5*time.Second, 100*time.Millisecond) checkUnaryServerSpans(t, serverUnarySR.Ended()) checkUnaryServerRecords(t, serverUnaryMetricReader) }) t.Run("StreamServerSpans", func(t *testing.T) { + require.EventuallyWithT(t, func(c *assert.CollectT) { + assert.Len(c, serverStreamSR.Ended(), 3) + }, 5*time.Second, 100*time.Millisecond) checkStreamServerSpans(t, serverStreamSR.Ended()) }) } From 89e9aad312d4bb42bf8b811fd53b4d00a426d411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 7 Nov 2023 09:51:14 +0100 Subject: [PATCH 2/2] Cleanup --- .../grpc/otelgrpc/test/grpc_test.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index 6a9a48ab130..d1837ee0bf1 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -133,31 +133,25 @@ func TestInterceptors(t *testing.T) { require.NoError(t, err) t.Run("UnaryClientSpans", func(t *testing.T) { - require.EventuallyWithT(t, func(c *assert.CollectT) { - assert.Len(c, clientUnarySR.Ended(), 2) - }, 5*time.Second, 100*time.Millisecond) checkUnaryClientSpans(t, clientUnarySR.Ended(), listener.Addr().String()) }) t.Run("StreamClientSpans", func(t *testing.T) { + // StreamClientInterceptor ends the spans asynchronously. + // We need to wait for all spans before asserting them. require.EventuallyWithT(t, func(c *assert.CollectT) { assert.Len(c, clientStreamSR.Ended(), 3) }, 5*time.Second, 100*time.Millisecond) + checkStreamClientSpans(t, clientStreamSR.Ended(), listener.Addr().String()) }) t.Run("UnaryServerSpans", func(t *testing.T) { - require.EventuallyWithT(t, func(c *assert.CollectT) { - assert.Len(c, serverUnarySR.Ended(), 2) - }, 5*time.Second, 100*time.Millisecond) checkUnaryServerSpans(t, serverUnarySR.Ended()) checkUnaryServerRecords(t, serverUnaryMetricReader) }) t.Run("StreamServerSpans", func(t *testing.T) { - require.EventuallyWithT(t, func(c *assert.CollectT) { - assert.Len(c, serverStreamSR.Ended(), 3) - }, 5*time.Second, 100*time.Millisecond) checkStreamServerSpans(t, serverStreamSR.Ended()) }) }