Periodic.Test (parent v0.13.0)

Copy Markdown View Source

Helpers for testing a periodic job.

See the "Testing" section in Periodic documentation for details.

Summary

Functions

Subscribes to telemetry events of the given scheduler.

Sends a tick signal to the given scheduler and waits for the job to finish.

Sends a tick signal to the given scheduler.

Functions

assert_periodic_event(telemetry_id, event, metadata \\ quote do _ end, measurements \\ quote do _ end)

(macro)

Waits for the given telemetry event.

observe(telemetry_id)

@spec observe(any()) :: :ok

Subscribes to telemetry events of the given scheduler.

refute_periodic_event(telemetry_id, event, metadata \\ quote do _ end, measurements \\ quote do _ end)

(macro)

Asserts that the given telemetry event won't be emitted.

sync_tick(pid_or_name, timeout \\ :timer.seconds(5))

@spec sync_tick(GenServer.server(), non_neg_integer() | :infinity) ::
  {:ok, job_exit_reason :: any()}
  | {:error, :job_not_started | :not_in_manual_mode}

Sends a tick signal to the given scheduler and waits for the job to finish.

The function returns the job exit reason, or error if the job hasn't been started.

If the scheduler was not started with :mode set to :manual, this function returns {:error, :not_in_manual_mode}.

tick(pid_or_name)

@spec tick(GenServer.server()) :: :ok | {:error, :not_in_manual_mode}

Sends a tick signal to the given scheduler.

This function returns after the tick signal has been sent, and the job has been started. However, the function doesn't wait for the job to finish. If you want complete synchronism, use sync_tick/2.

If the scheduler was not started with :mode set to :manual, this function returns {:error, :not_in_manual_mode}.