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) }