code: def test_heartbeat(self, frozen_sleep, monkeypatch):
      monkeypatch.setattr("airflow.jobs.job.sleep", frozen_sleep)
      with create_session() as session:
          job = Job(heartrate=10)
          job.latest_heartbeat = timezone.utcnow()
          session.add(job)
          session.commit()
  
          hb_callback = Mock()
          job.heartbeat(heartbeat_callback=hb_callback)
  
          hb_callback.assert_called_once_with(ANY)
  
          hb_callback.reset_mock()
          perform_heartbeat(
              job=job,
              heartbeat_callback=hb_callback,
              only_if_necessary=True,
          )
          assert hb_callback.called is False
  
imports: from __future__ import annotations
  import datetime
  import sys
  from unittest.mock import ANY, Mock, patch
  import pytest
  from sqlalchemy.exc import OperationalError
  from airflow.executors.sequential_executor import SequentialExecutor
  from airflow.jobs.job import Job, most_recent_job, perform_heartbeat, run_job
  from airflow.listeners.listener import get_listener_manager
  from airflow.utils import timezone
  from airflow.utils.session import create_session
  from airflow.utils.state import State
  from tests.listeners import lifecycle_listener
  from tests.test_utils.config import conf_vars
  from tests.utils.test_helpers import MockJobRunner, SchedulerJobRunner, TriggererJobRunner
label_desc: Use image node_id 14 for calling the TestJob obj's underlying member method code with example usage: obj.test_heartbeat(frozen_sleep, monkeypatch) without return types