def test_catch_errors_in_heartbeat_thread(monkeypatch, runner_token, cloud_api, caplog): """Check that errors in the heartbeat thread are caught, logged, and the thread keeps going""" monkeypatch.setattr("prefect.agent.agent.Agent.agent_process", MagicMock()) monkeypatch.setattr( "prefect.agent.agent.Agent.agent_connect", MagicMock(return_value="id") ) heartbeat = MagicMock(side_effect=ValueError) monkeypatch.setattr("prefect.agent.agent.Agent.heartbeat", heartbeat) agent = Agent(max_polls=2) agent.heartbeat_period = 0.1 agent.start() assert heartbeat.call_count > 1 assert any("Error in agent heartbeat" in m for m in caplog.messages)
def test_catch_errors_in_heartbeat_thread(monkeypatch, cloud_api, caplog): """Check that errors in the heartbeat thread are caught, logged, and the thread keeps going""" monkeypatch.setattr( "prefect.agent.agent.Agent._submit_deploy_flow_run_jobs", MagicMock() ) monkeypatch.setattr( "prefect.agent.agent.Agent._setup_api_connection", MagicMock(return_value="id") ) heartbeat = MagicMock(side_effect=ValueError) monkeypatch.setattr("prefect.agent.agent.Agent.heartbeat", heartbeat) agent = Agent(max_polls=2) # Ignore registration agent._register_agent = MagicMock() agent.heartbeat_period = 0.1 agent.start() assert heartbeat.call_count > 1 assert any("Error in agent heartbeat" in m for m in caplog.messages)