Skip to content

Commit

Permalink
Adjust LV test sleep time
Browse files Browse the repository at this point in the history
  • Loading branch information
wmnnd committed Aug 11, 2024
1 parent 2f9b9fc commit 1479070
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
20 changes: 12 additions & 8 deletions lib/keila/mailings/schedule_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ defmodule Keila.Mailings.ScheduleWorker do
@impl true
def perform(%Oban.Job{}) do
Enum.reduce_while(1..@passes, :ok, fn _, _ ->
Repo.transaction(fn ->
if jobs_below_threshold?() do
schedule_recipients()
{:cont, :ok}
else
{:halt, :ok}
end
end)
{_, acc} =
Repo.transaction(fn ->
if jobs_below_threshold?() do
schedule_recipients()
{:cont, :ok}
else
{:halt, :ok}
end
end)

acc
end)
end

Expand All @@ -58,6 +61,7 @@ defmodule Keila.Mailings.ScheduleWorker do
limit: @limit,
lock: "FOR NO KEY UPDATE"
)
|> Repo.all()
|> Enum.group_by(& &1.campaign_id)
|> Enum.each(fn {campaign_id, recipients} ->
insert_jobs(campaign_id, recipients)
Expand Down
12 changes: 6 additions & 6 deletions test/keila/mailings/mailings_campaign_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ defmodule Keila.MailingsCampaignTest do

assert :ok = Mailings.deliver_campaign(campaign.id)

Oban.drain_queue(queue: :periodic)
assert %{success: 1} = Oban.drain_queue(queue: :periodic)
assert %{success: ^n, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true)

for _ <- 1..n do
Expand Down Expand Up @@ -122,7 +122,7 @@ defmodule Keila.MailingsCampaignTest do

assert :ok = Mailings.deliver_campaign(campaign.id)

Oban.drain_queue(queue: :periodic)
assert %{success: 1} = Oban.drain_queue(queue: :periodic)

assert %{success: ^n_expected_sent, failure: 0, snoozed: ^n_expected_snoozed} =
Oban.drain_queue(queue: :mailer, with_scheduled: true)
Expand Down Expand Up @@ -161,7 +161,7 @@ defmodule Keila.MailingsCampaignTest do

assert :ok = Mailings.deliver_campaign(campaign.id)

Oban.drain_queue(queue: :periodic)
assert %{success: 1} = Oban.drain_queue(queue: :periodic)
assert %{success: ^n, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true)

for _ <- 1..n do
Expand All @@ -186,7 +186,7 @@ defmodule Keila.MailingsCampaignTest do

assert :ok = Mailings.deliver_campaign(campaign.id)

Oban.drain_queue(queue: :periodic)
assert %{success: 1} = Oban.drain_queue(queue: :periodic)
assert %{success: ^n, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true)

for _ <- 1..n do
Expand Down Expand Up @@ -308,7 +308,7 @@ defmodule Keila.MailingsCampaignTest do
)

assert :ok = Mailings.deliver_campaign(campaign.id)
Oban.drain_queue(queue: :periodic)
assert %{success: 1} = Oban.drain_queue(queue: :periodic)
assert %{success: 1, failure: 0} = Oban.drain_queue(queue: :mailer, with_scheduled: true)

receive do
Expand Down Expand Up @@ -343,7 +343,7 @@ defmodule Keila.MailingsCampaignTest do

assert :ok = Mailings.deliver_campaign(campaign.id)

Oban.drain_queue(queue: :periodic)
assert %{success: 1} = Oban.drain_queue(queue: :periodic)
assert %{success: 1, cancelled: 1} = Oban.drain_queue(queue: :mailer, with_scheduled: true)
assert %{status: :sent} = Mailings.get_campaign_stats(campaign.id)
end
Expand Down
2 changes: 1 addition & 1 deletion test/keila_web/controllers/campaign_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ defmodule KeilaWeb.CampaignControllerTest do

Oban.drain_queue(queue: :periodic)
Oban.drain_queue(queue: :mailer, with_scheduled: true)
:timer.sleep(500)
:timer.sleep(1500)

assert render(lv) =~
"<div class=\"text-sm\">emails sent</div><div class=\"text-3xl\">10</div>"
Expand Down

0 comments on commit 1479070

Please sign in to comment.