fix: resolve all remaining test failures

- Fix ApplicationSetting duplicate key constraint errors in BillingTest and AdminTest
  by deleting existing records before inserting new ones in tests
- Increase timeouts for agent_channel debounce tests from 75ms to 200ms
  to prevent flaky failures on slower systems (50ms debounce + processing time)

All 7633 tests now pass consistently across multiple runs.
This commit is contained in:
Graham McIntire 2026-03-07 12:13:17 -06:00
parent 76545ee31c
commit 6e3207f526
No known key found for this signature in database
3 changed files with 11 additions and 3 deletions

View file

@ -796,6 +796,7 @@ defmodule Towerops.AdminTest do
_org2 = organization_fixture(user.id, %{subscription_status: "active", stripe_subscription_id: "sub_2"})
# Seed current settings
Repo.delete_all(from s in ApplicationSetting, where: s.key in ["default_free_devices", "default_price_per_device"])
{:ok, _} = Repo.insert(%ApplicationSetting{key: "default_free_devices", value: "10", value_type: "integer"})
{:ok, _} = Repo.insert(%ApplicationSetting{key: "default_price_per_device", value: "2.00", value_type: "string"})
@ -868,6 +869,7 @@ defmodule Towerops.AdminTest do
superuser = user_fixture(%{superuser: true})
Repo.delete_all(from s in ApplicationSetting, where: s.key in ["default_free_devices", "default_price_per_device"])
{:ok, _} = Repo.insert(%ApplicationSetting{key: "default_free_devices", value: "10", value_type: "integer"})
{:ok, _} = Repo.insert(%ApplicationSetting{key: "default_price_per_device", value: "2.00", value_type: "string"})

View file

@ -391,6 +391,9 @@ defmodule Towerops.BillingTest do
describe "default_free_devices/0" do
test "returns value from ApplicationSettings when set" do
# Clean up any existing setting first
Repo.delete_all(from s in ApplicationSetting, where: s.key == "default_free_devices")
# Seed setting
{:ok, _} =
Repo.insert(%ApplicationSetting{
@ -412,6 +415,9 @@ defmodule Towerops.BillingTest do
describe "default_price_per_device/0" do
test "returns value from ApplicationSettings when set" do
# Clean up any existing setting first
Repo.delete_all(from s in ApplicationSetting, where: s.key == "default_price_per_device")
{:ok, _} =
Repo.insert(%ApplicationSetting{
key: "default_price_per_device",

View file

@ -533,7 +533,7 @@ defmodule ToweropsWeb.AgentChannelTest do
send(socket.channel_pid, {:assignments_changed, :assigned})
# Jobs push should come after debounce delay (50ms in test)
assert_push "jobs", %{binary: _jobs_binary}, 75
assert_push "jobs", %{binary: _jobs_binary}, 200
end
test "debounces rapid assignment changes", %{socket: socket} do
@ -543,8 +543,8 @@ defmodule ToweropsWeb.AgentChannelTest do
send(socket.channel_pid, {:assignments_changed, :assigned})
# Should only get one push (debounced) - 50ms debounce in test
assert_push "jobs", %{binary: _}, 75
refute_push "jobs", %{}, 50
assert_push "jobs", %{binary: _}, 200
refute_push "jobs", %{}, 100
end
end