Skip to content

Commit d7a47a7

Browse files
committed
refactor: improve HTTP client usage in readiness endpoint tests
1 parent 76e1357 commit d7a47a7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

node/single_sequencer_integration_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ func waitForBlockN(t *testing.T, n uint64, node *FullNode, blockInterval time.Du
422422
func TestReadinessEndpointWhenBlockProductionStops(t *testing.T) {
423423
require := require.New(t)
424424

425+
httpClient := &http.Client{Timeout: 1 * time.Second}
426+
425427
config := getTestConfig(t, 1)
426428
config.Node.Aggregator = true
427429
config.Node.BlockTime = evconfig.DurationWrapper{Duration: 500 * time.Millisecond}
@@ -439,10 +441,14 @@ func TestReadinessEndpointWhenBlockProductionStops(t *testing.T) {
439441

440442
waitForBlockN(t, 1, node, config.Node.BlockTime.Duration)
441443

442-
resp, err := http.Get("http://" + config.RPC.Address + "/health/ready")
443-
require.NoError(err)
444-
require.Equal(http.StatusOK, resp.StatusCode, "Readiness should be READY while producing blocks")
445-
resp.Body.Close()
444+
require.Eventually(func() bool {
445+
resp, err := httpClient.Get("http://" + config.RPC.Address + "/health/ready")
446+
if err != nil {
447+
return false
448+
}
449+
defer resp.Body.Close()
450+
return resp.StatusCode == http.StatusOK
451+
}, 10*time.Second, 100*time.Millisecond, "Readiness should be READY while producing blocks")
446452

447453
time.Sleep(time.Duration(config.Node.MaxPendingHeadersAndData+2) * config.Node.BlockTime.Duration)
448454

@@ -451,7 +457,7 @@ func TestReadinessEndpointWhenBlockProductionStops(t *testing.T) {
451457
require.LessOrEqual(height, config.Node.MaxPendingHeadersAndData)
452458

453459
require.Eventually(func() bool {
454-
resp, err := http.Get("http://" + config.RPC.Address + "/health/ready")
460+
resp, err := httpClient.Get("http://" + config.RPC.Address + "/health/ready")
455461
if err != nil {
456462
return false
457463
}

0 commit comments

Comments
 (0)