@@ -1188,30 +1188,44 @@ def test_do_not_crash_on_version_collection_failure():
11881188
11891189
11901190@pytest .mark .unit
1191- def test_driver_startup_message_retry_forever (caplog ):
1192- """Default behavior (startup_wait_retries=0): retry forever, never raise."""
1191+ def test_driver_startup_message_default_retries (aggregator , caplog ):
1192+ """Default behavior (startup_wait_retries=3): retry 3 times then raise."""
1193+ from simplejson import JSONDecodeError
1194+
11931195 check = SparkCheck ('spark' , {}, [DRIVER_CONFIG ])
11941196 response = MockResponse (content = "Spark is starting up. Please wait a while until it's ready." )
11951197
11961198 with caplog .at_level (logging .DEBUG ):
11971199 with mock .patch .object (check , '_rest_request' , return_value = response ):
1198- # Call multiple times - should always return None
1199- for _ in range (5 ):
1200+ # First 3 attempts should return None (default is 3 retries)
1201+ for i in range (3 ):
12001202 result = check ._rest_request_to_json (
12011203 DRIVER_CONFIG ['spark_url' ], SPARK_REST_PATH , SPARK_DRIVER_SERVICE_CHECK , []
12021204 )
1203- assert result is None
1205+ assert result is None , f"Attempt { i + 1 } should return None"
1206+
1207+ # 4th attempt should raise
1208+ with pytest .raises (JSONDecodeError ):
1209+ check ._rest_request_to_json (DRIVER_CONFIG ['spark_url' ], SPARK_REST_PATH , SPARK_DRIVER_SERVICE_CHECK , [])
12041210
12051211 assert 'spark driver not ready yet' in caplog .text .lower ()
1212+ assert 'retries exhausted' in caplog .text .lower ()
1213+
1214+ aggregator .assert_service_check (
1215+ SPARK_DRIVER_SERVICE_CHECK ,
1216+ status = SparkCheck .CRITICAL ,
1217+ tags = ['url:{}' .format (DRIVER_CONFIG ['spark_url' ])],
1218+ )
12061219
12071220
12081221@pytest .mark .unit
1209- def test_driver_startup_message_disabled (aggregator ):
1210- """When startup_wait_retries=-1, treat startup messages as errors immediately."""
1222+ @pytest .mark .parametrize ("retries_value" , [0 , - 1 , - 5 ])
1223+ def test_driver_startup_message_disabled (aggregator , retries_value ):
1224+ """When startup_wait_retries<=0, treat startup messages as errors immediately."""
12111225 from simplejson import JSONDecodeError
12121226
12131227 config = DRIVER_CONFIG .copy ()
1214- config ['startup_wait_retries' ] = - 1
1228+ config ['startup_wait_retries' ] = retries_value
12151229 check = SparkCheck ('spark' , {}, [config ])
12161230 response = MockResponse (content = "Spark is starting up. Please wait a while until it's ready." )
12171231
0 commit comments