Skip to content

Commit

Permalink
Retain time as microseconds for scheduled_at tests
Browse files Browse the repository at this point in the history
Include microseconds in the `begin` and `until` times used for scheduled_at
tests with a delta. The prior version would truncate, which rounded the
`until` down and broke microsecond level checks.

Closes #1162
  • Loading branch information
sorentwo committed Oct 21, 2024
1 parent 13b27ea commit 908318d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/oban/testing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,10 @@ defmodule Oban.Testing do
time -> {time, 1}
end

{:ok, time} = Ecto.Type.cast(:utc_datetime, time)
datetime = Ecto.Type.cast!(:utc_datetime_usec, time)

begin = DateTime.add(time, -delta, :second)
until = DateTime.add(time, +delta, :second)
begin = DateTime.add(datetime, -delta, :second)
until = DateTime.add(datetime, +delta, :second)

where(query, [j], fragment("? BETWEEN ? AND ?", field(j, ^key), ^begin, ^until))
end
Expand Down
2 changes: 2 additions & 0 deletions test/oban/testing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ defmodule Oban.TestingTest do
test "checking for jobs with matching timestamps within delta" do
insert!(%{}, worker: Ping)
insert!(%{}, worker: Pong, scheduled_at: seconds_from_now(60))
insert!(%{}, worker: Pong, scheduled_at: ~U[2000-10-20 05:10:31.057748Z])

assert_enqueued worker: Ping, state: "available", scheduled_at: DateTime.utc_now()
assert_enqueued worker: Ping, scheduled_at: DateTime.now!("America/Chicago")
assert_enqueued worker: Pong, scheduled_at: seconds_from_now(60)
assert_enqueued worker: Pong, scheduled_at: {seconds_from_now(69), delta: 10}
assert_enqueued worker: Pong, scheduled_at: ~U[2000-10-20 05:10:30.557748Z]
end

test "asserting that jobs are now or will eventually be enqueued" do
Expand Down

0 comments on commit 908318d

Please sign in to comment.