@@ -232,3 +232,71 @@ func TestHealthReady_aggregatorBlockDelay(t *testing.T) {
232232 })
233233 }
234234}
235+
236+ func TestHealthReady_nonAggregatorBlockDelay (t * testing.T ) {
237+ logger := zerolog .Nop ()
238+
239+ type spec struct {
240+ readinessWindowSeconds uint64
241+ delay time.Duration
242+ expStatusCode int
243+ expBody string
244+ }
245+
246+ specs := map [string ]spec {
247+ "within readiness window" : {
248+ readinessWindowSeconds : 10 ,
249+ delay : 5 * time .Second ,
250+ expStatusCode : http .StatusOK ,
251+ expBody : "READY\n " ,
252+ },
253+ "exceeds readiness window" : {
254+ readinessWindowSeconds : 10 ,
255+ delay : 15 * time .Second ,
256+ expStatusCode : http .StatusServiceUnavailable ,
257+ expBody : "UNREADY: node not executing blocks\n " ,
258+ },
259+ "zero readiness window falls back to default 15s" : {
260+ readinessWindowSeconds : 0 ,
261+ delay : 10 * time .Second ,
262+ expStatusCode : http .StatusOK ,
263+ expBody : "READY\n " ,
264+ },
265+ }
266+
267+ for name , tc := range specs {
268+ t .Run (name , func (t * testing.T ) {
269+ mux := http .NewServeMux ()
270+
271+ cfg := config .DefaultConfig ()
272+ cfg .Node .Aggregator = false
273+ cfg .Node .ReadinessWindowSeconds = tc .readinessWindowSeconds
274+
275+ mockStore := mocks .NewMockStore (t )
276+ state := types.State {
277+ LastBlockHeight : 10 ,
278+ LastBlockTime : time .Now ().Add (- tc .delay ),
279+ }
280+ mockStore .On ("GetState" , mock .Anything ).Return (state , nil )
281+
282+ bestKnownHeightProvider := func () uint64 { return state .LastBlockHeight }
283+
284+ RegisterCustomHTTPEndpoints (mux , mockStore , nil , cfg , bestKnownHeightProvider , logger , nil )
285+
286+ ts := httptest .NewServer (mux )
287+ t .Cleanup (ts .Close )
288+
289+ req , err := http .NewRequest (http .MethodGet , ts .URL + "/health/ready" , nil )
290+ require .NoError (t , err )
291+ resp , err := http .DefaultClient .Do (req ) //nolint:gosec // ok to use default client in tests
292+ require .NoError (t , err )
293+ t .Cleanup (func () { _ = resp .Body .Close () })
294+
295+ body , err := io .ReadAll (resp .Body )
296+ require .NoError (t , err )
297+
298+ assert .Equal (t , tc .expStatusCode , resp .StatusCode )
299+ assert .Equal (t , tc .expBody , string (body ))
300+ })
301+ }
302+ }
0 commit comments