@@ -282,3 +282,62 @@ def mock_main():
282282 "partitionId" : "2" ,
283283 "taskAttemptId" : "3" ,
284284 }
285+
286+
287+ def test_sentry_listener_on_stage_submitted_no_attempt_id (sentry_listener ):
288+ listener = sentry_listener
289+ with patch .object (listener , "_add_breadcrumb" ) as mock_add_breadcrumb :
290+
291+ class StageInfo :
292+ def stageId (self ): # noqa: N802
293+ return "sample-stage-id-submit"
294+
295+ def name (self ):
296+ return "run-job"
297+
298+ def attemptName (self ): # noqa: N802
299+ return 14
300+
301+ class MockStageSubmitted :
302+ def stageInfo (self ): # noqa: N802
303+ stageinf = StageInfo ()
304+ return stageinf
305+
306+ mock_stage_submitted = MockStageSubmitted ()
307+ listener .onStageSubmitted (mock_stage_submitted )
308+
309+ mock_add_breadcrumb .assert_called_once ()
310+ mock_hub = mock_add_breadcrumb .call_args
311+
312+ assert mock_hub .kwargs ["level" ] == "info"
313+ assert "sample-stage-id-submit" in mock_hub .kwargs ["message" ]
314+ assert mock_hub .kwargs ["data" ]["attemptId" ] == 14
315+ assert mock_hub .kwargs ["data" ]["name" ] == "run-job"
316+
317+
318+ def test_sentry_listener_on_stage_submitted_no_attempt_id_or_number (sentry_listener ):
319+ listener = sentry_listener
320+ with patch .object (listener , "_add_breadcrumb" ) as mock_add_breadcrumb :
321+
322+ class StageInfo :
323+ def stageId (self ): # noqa: N802
324+ return "sample-stage-id-submit"
325+
326+ def name (self ):
327+ return "run-job"
328+
329+ class MockStageSubmitted :
330+ def stageInfo (self ): # noqa: N802
331+ stageinf = StageInfo ()
332+ return stageinf
333+
334+ mock_stage_submitted = MockStageSubmitted ()
335+ listener .onStageSubmitted (mock_stage_submitted )
336+
337+ mock_add_breadcrumb .assert_called_once ()
338+ mock_hub = mock_add_breadcrumb .call_args
339+
340+ assert mock_hub .kwargs ["level" ] == "info"
341+ assert "sample-stage-id-submit" in mock_hub .kwargs ["message" ]
342+ assert "attemptId" not in mock_hub .kwargs ["data" ]
343+ assert mock_hub .kwargs ["data" ]["name" ] == "run-job"
0 commit comments