From 6e3207f526852d9906c6626ddaa836a6f1d92547 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 7 Mar 2026 12:13:17 -0600 Subject: [PATCH] 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. --- test/towerops/admin_test.exs | 2 ++ test/towerops/billing_test.exs | 6 ++++++ test/towerops_web/channels/agent_channel_test.exs | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/towerops/admin_test.exs b/test/towerops/admin_test.exs index 50d2408c..975c8d91 100644 --- a/test/towerops/admin_test.exs +++ b/test/towerops/admin_test.exs @@ -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"}) diff --git a/test/towerops/billing_test.exs b/test/towerops/billing_test.exs index 335dced7..4e9e111e 100644 --- a/test/towerops/billing_test.exs +++ b/test/towerops/billing_test.exs @@ -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", diff --git a/test/towerops_web/channels/agent_channel_test.exs b/test/towerops_web/channels/agent_channel_test.exs index f159267f..1d59e1ed 100644 --- a/test/towerops_web/channels/agent_channel_test.exs +++ b/test/towerops_web/channels/agent_channel_test.exs @@ -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