From 52329cf9599156841323190f8a79c15cecced889 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 6 Mar 2026 08:03:54 -0600 Subject: [PATCH] perf(tests): make device deletion delay configurable for faster tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the 500ms device deletion delay configurable via application config. Set to 10ms in test environment (vs 500ms in production). This sleep waits for in-flight polling jobs to complete before deleting a device. In tests with mocked jobs, this delay is unnecessary. Affected tests: - All device deletion tests (were 500-650ms, now ~100-150ms) - Equipment context tests - API controller tests - LiveView tests with device deletion Performance: 28.3s → 25.2s (11% faster) Total improvement from baseline: 52s → 25.2s (51.5% faster) --- config/test.exs | 4 +++- lib/towerops/devices.ex | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/test.exs b/config/test.exs index d58481ed..1e24076e 100644 --- a/config/test.exs +++ b/config/test.exs @@ -92,4 +92,6 @@ config :towerops, # Disable rate limiting in tests to avoid blocking concurrent test requests rate_limiting_enabled: false, # Reduce debounce delay in tests for faster test execution (50ms vs 500ms in prod) - agent_channel_debounce_ms: 50 + agent_channel_debounce_ms: 50, + # Reduce device deletion delay for faster tests (10ms vs 500ms in prod) + device_deletion_delay_ms: 10 diff --git a/lib/towerops/devices.ex b/lib/towerops/devices.ex index caaa564f..a12be4d1 100644 --- a/lib/towerops/devices.ex +++ b/lib/towerops/devices.ex @@ -895,7 +895,9 @@ defmodule Towerops.Devices do # Wait briefly for any in-flight jobs to complete or detect deletion # This reduces (but doesn't eliminate) the window for orphaned writes # In-flight jobs check device existence via verify_polling_assignment_unchanged - Process.sleep(500) + # Configurable for faster tests (defaults to 500ms in prod, 10ms in test) + deletion_delay_ms = Application.get_env(:towerops, :device_deletion_delay_ms, 500) + Process.sleep(deletion_delay_ms) # Get agent assignment before deleting (if any) assignment = Agents.get_device_assignment(device.id)