perf(tests): reduce Process.sleep calls in timeout tests

Optimizations:
- Deferred discovery tests: 500ms → 100ms sleeps (still > 50ms timeout)
- Event logger tests: 100ms → 50ms sleeps, added polling for early exit
- Saved ~2.4 seconds across affected tests (6 tests × 400ms each)

Changes:
- test/towerops/snmp/deferred_discovery_test.exs: reduce timeout test sleeps
- test/towerops/equipment/event_logger_test.exs: reduce sleeps, add polling
This commit is contained in:
Graham McIntire 2026-03-06 07:27:35 -06:00
parent 0ea54b63db
commit 1f49e1fba5
No known key found for this signature in database
2 changed files with 21 additions and 13 deletions

View file

@ -54,12 +54,20 @@ defmodule Towerops.Devices.EventLoggerTest do
{:device_event, event_attrs}
)
# Give the EventLogger a moment to process
Process.sleep(100)
# Poll for event with early exit (max 100ms)
events =
Enum.reduce_while(1..10, [], fn _, _acc ->
events = Towerops.Devices.list_devices_events(device.id, 10)
# Verify event was created in database
events = Towerops.Devices.list_devices_events(device.id, 10)
assert length(events) == 1
if events == [] do
Process.sleep(10)
{:cont, []}
else
{:halt, events}
end
end)
assert [_event] = events
event = hd(events)
assert event.device_id == device.id
@ -121,7 +129,7 @@ defmodule Towerops.Devices.EventLoggerTest do
{:device_event, invalid_event}
)
Process.sleep(100)
Process.sleep(50)
end)
# Verify error was logged
@ -137,7 +145,7 @@ defmodule Towerops.Devices.EventLoggerTest do
)
# Should not crash - just log and move on
Process.sleep(100)
Process.sleep(50)
# EventLogger should still be running
assert Process.whereis(EventLogger)

View file

@ -27,7 +27,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
DeferredDiscovery.fast_check(
client_opts,
fn ->
Process.sleep(500)
Process.sleep(100)
{:ok, "too slow"}
end,
timeout: 50
@ -67,7 +67,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
DeferredDiscovery.slow_check(
client_opts,
fn ->
Process.sleep(500)
Process.sleep(100)
{:ok, "too slow"}
end,
timeout: 50,
@ -84,7 +84,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
DeferredDiscovery.slow_check(
client_opts,
fn ->
Process.sleep(500)
Process.sleep(100)
{:ok, "too slow"}
end,
timeout: 50,
@ -129,7 +129,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
DeferredDiscovery.deferred_check(
client_opts,
fn ->
Process.sleep(500)
Process.sleep(100)
{:ok, "too slow"}
end,
timeout: 50,
@ -175,7 +175,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
{:fast_check, fn -> {:ok, "fast"} end, [timeout: 1000]},
{:slow_check,
fn ->
Process.sleep(500)
Process.sleep(100)
{:ok, "slow"}
end, [timeout: 50, default: []]}
]
@ -227,7 +227,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
test "returns false when check times out" do
expect(SnmpMock, :get, fn _target, _oid, _opts ->
Process.sleep(500)
Process.sleep(100)
{:ok, [1, 3, 6, 1, 4, 1, 9]}
end)