rpc: fix flaky otel tests (#35101)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

The response can reach the client before the deferred spanEnd fires, so
call `httpsrv.Close()` before GetSpans is called.
This commit is contained in:
Jonny Rhea 2026-06-02 12:50:57 -05:00 committed by GitHub
parent 38667bc64e
commit e514ede494
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -470,6 +470,10 @@ func TestTracingBatchHTTPEmpty(t *testing.T) {
postJSONRPC(t, httpsrv.URL, `[]`) 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 { if err := tracer.ForceFlush(context.Background()); err != nil {
t.Fatalf("failed to flush: %v", err) t.Fatalf("failed to flush: %v", err)
} }
@ -510,6 +514,10 @@ func TestTracingBatchHTTPTooLarge(t *testing.T) {
]` ]`
postJSONRPC(t, httpsrv.URL, body) 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 { if err := tracer.ForceFlush(context.Background()); err != nil {
t.Fatalf("failed to flush: %v", err) t.Fatalf("failed to flush: %v", err)
} }
@ -553,6 +561,10 @@ func TestTracingHTTPTimeout(t *testing.T) {
// response goes out. // response goes out.
postJSONRPC(t, httpsrv.URL, `{"jsonrpc":"2.0","id":1,"method":"test_block"}`) 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 { if err := tracer.ForceFlush(context.Background()); err != nil {
t.Fatalf("failed to flush: %v", err) t.Fatalf("failed to flush: %v", err)
} }