test: add missing assertions for ordering and worker filtering

This commit is contained in:
Graham McIntire 2026-02-06 16:17:26 -06:00 committed by Graham McIntire
parent 35c7328831
commit b2cc622036
No known key found for this signature in database

View file

@ -10,20 +10,19 @@ defmodule Towerops.JobMonitoringTest do
test "returns jobs in executing state for polling and discovery workers" do
device = device_fixture()
# Create executing polling job
oban_job_fixture(%{
# Create jobs with different attempted_at times
older_job = oban_job_fixture(%{
worker: "Towerops.Workers.DevicePollerWorker",
state: "executing",
args: %{"device_id" => device.id},
attempted_at: DateTime.utc_now()
attempted_at: DateTime.add(DateTime.utc_now(), -60, :second) # 60 seconds ago
})
# Create executing discovery job
oban_job_fixture(%{
newer_job = oban_job_fixture(%{
worker: "Towerops.Workers.DiscoveryWorker",
state: "executing",
args: %{"device_id" => device.id},
attempted_at: DateTime.utc_now()
attempted_at: DateTime.utc_now() # Now
})
# Create completed job (should not be returned)
@ -37,6 +36,36 @@ defmodule Towerops.JobMonitoringTest do
assert length(jobs) == 2
assert Enum.all?(jobs, fn j -> j.state == "executing" end)
# Verify ascending order by attempted_at
assert hd(jobs).id == older_job.id
assert List.last(jobs).id == newer_job.id
end
test "excludes jobs from other workers" do
device = device_fixture()
# Create job from non-monitored worker
oban_job_fixture(%{
worker: "Towerops.Workers.SomeOtherWorker",
state: "executing",
args: %{"device_id" => device.id},
attempted_at: DateTime.utc_now()
})
# Create job from monitored worker
oban_job_fixture(%{
worker: "Towerops.Workers.DevicePollerWorker",
state: "executing",
args: %{"device_id" => device.id},
attempted_at: DateTime.utc_now()
})
jobs = JobMonitoring.list_active_jobs()
# Should only return the DevicePollerWorker job
assert length(jobs) == 1
assert hd(jobs).worker == "Towerops.Workers.DevicePollerWorker"
end
end
end