From e514ede4946e6fdc0c9b095a52878d731df82149 Mon Sep 17 00:00:00 2001 From: Jonny Rhea <5555162+jrhea@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:50:57 -0500 Subject: [PATCH] rpc: fix flaky otel tests (#35101) The response can reach the client before the deferred spanEnd fires, so call `httpsrv.Close()` before GetSpans is called. --- rpc/tracing_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rpc/tracing_test.go b/rpc/tracing_test.go index 302dff1384..58dc2f1758 100644 --- a/rpc/tracing_test.go +++ b/rpc/tracing_test.go @@ -470,6 +470,10 @@ func TestTracingBatchHTTPEmpty(t *testing.T) { postJSONRPC(t, httpsrv.URL, `[]`) + // Wait for the in-flight request to finish so the deferred spanEnd fires + // before GetSpans is called. + httpsrv.Close() + if err := tracer.ForceFlush(context.Background()); err != nil { t.Fatalf("failed to flush: %v", err) } @@ -510,6 +514,10 @@ func TestTracingBatchHTTPTooLarge(t *testing.T) { ]` postJSONRPC(t, httpsrv.URL, body) + // Wait for the in-flight request to finish so the deferred spanEnd fires + // before GetSpans is called. + httpsrv.Close() + if err := tracer.ForceFlush(context.Background()); err != nil { t.Fatalf("failed to flush: %v", err) } @@ -553,6 +561,10 @@ func TestTracingHTTPTimeout(t *testing.T) { // response goes out. postJSONRPC(t, httpsrv.URL, `{"jsonrpc":"2.0","id":1,"method":"test_block"}`) + // Wait for the in-flight request to finish so the deferred spanEnd fires + // before GetSpans is called. + httpsrv.Close() + if err := tracer.ForceFlush(context.Background()); err != nil { t.Fatalf("failed to flush: %v", err) }