def test_custom_interval_sensor_with_offset(external_repo_context, monkeypatch): freeze_datetime = to_timezone( create_pendulum_time(year=2019, month=2, day=28, tz="UTC"), "US/Central") sleeps = [] def fake_sleep(s): sleeps.append(s) pendulum.set_test_now(pendulum.now().add(seconds=s)) monkeypatch.setattr(time, "sleep", fake_sleep) with instance_with_sensors(external_repo_context) as ( instance, grpc_server_registry, external_repo, ): with pendulum.test(freeze_datetime): # 60 second custom interval external_sensor = external_repo.get_external_sensor( "custom_interval_sensor") instance.add_job_state( JobState(external_sensor.get_external_origin(), JobType.SENSOR, JobStatus.RUNNING)) # create a tick evaluate_sensors(instance, grpc_server_registry) ticks = instance.get_job_ticks( external_sensor.get_external_origin_id()) assert len(ticks) == 1 # calling for another iteration should not generate another tick because time has not # advanced evaluate_sensors(instance, grpc_server_registry) ticks = instance.get_job_ticks( external_sensor.get_external_origin_id()) assert len(ticks) == 1 # call the sensor_iteration_loop, which should loop, and call the monkeypatched sleep # to advance 30 seconds list( execute_sensor_iteration_loop( instance, grpc_server_registry, get_default_daemon_logger("SensorDaemon"), daemon_shutdown_event=None, until=freeze_datetime.add(seconds=65).timestamp(), )) assert pendulum.now() == freeze_datetime.add(seconds=65) ticks = instance.get_job_ticks( external_sensor.get_external_origin_id()) assert len(ticks) == 2 assert sum(sleeps) == 65
def run_iteration(self, instance, workspace): yield from execute_sensor_iteration_loop(instance, workspace, self._logger)
def run_iteration(self, instance, grpc_server_registry): yield from execute_sensor_iteration_loop(instance, grpc_server_registry, self._logger)
def run_iteration(self, instance, daemon_shutdown_event, grpc_server_registry): yield from execute_sensor_iteration_loop(instance, grpc_server_registry, self._logger, daemon_shutdown_event)