perf(tests): aggressive timeout and delay reductions
Major reductions across test suite: - Error handler backoff delays: 100ms→20ms, 50ms→10ms - Sensor change detector refute_receive: 100ms→50ms - Agent channel assert_receive: 5000ms→1000ms, 2000ms→500ms - Agent channel assert_push: 5000ms→1000ms - Deferred discovery timeout sleeps: 60ms→55ms - Event logger sleeps: 25ms→10ms - Validator test: 50,100 OIDs→50,001 (minimum to test rejection) Performance: 28s → 26.8s (4.3% faster) Total from baseline: 52s → 26.8s (48.5% faster)
This commit is contained in:
parent
bc7922f476
commit
b5e8e00dcb
5 changed files with 23 additions and 23 deletions
|
|
@ -79,15 +79,15 @@ defmodule SnmpKit.SnmpLib.ErrorHandlerTest do
|
|||
|
||||
ErrorHandler.with_retry(fun,
|
||||
max_attempts: 2,
|
||||
base_delay: 100,
|
||||
base_delay: 20,
|
||||
strategy: :fixed,
|
||||
jitter_factor: 0
|
||||
)
|
||||
|
||||
end_time = System.monotonic_time(:millisecond)
|
||||
|
||||
# Should have at least one 100ms delay (allow for some timing variance)
|
||||
assert end_time - start_time >= 90
|
||||
# Should have at least one 20ms delay (allow for some timing variance)
|
||||
assert end_time - start_time >= 18
|
||||
end
|
||||
|
||||
test "uses exponential backoff strategy" do
|
||||
|
|
@ -101,7 +101,7 @@ defmodule SnmpKit.SnmpLib.ErrorHandlerTest do
|
|||
|
||||
ErrorHandler.with_retry(fun,
|
||||
max_attempts: 3,
|
||||
base_delay: 50,
|
||||
base_delay: 10,
|
||||
strategy: :exponential,
|
||||
jitter_factor: 0
|
||||
)
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ defmodule Towerops.Agent.ValidatorTest do
|
|||
|
||||
test "rejects too many OID values" do
|
||||
# Create map with more than max allowed OIDs (max is 50_000)
|
||||
oid_values = Map.new(1..50_100, fn i -> {"1.3.6.1.#{i}", "value"} end)
|
||||
oid_values = Map.new(1..50_001, fn i -> {"1.3.6.1.#{i}", "value"} end)
|
||||
|
||||
result = %SnmpResult{
|
||||
device_id: "550e8400-e29b-41d4-a716-446655440000",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
|
|||
DeferredDiscovery.fast_check(
|
||||
client_opts,
|
||||
fn ->
|
||||
Process.sleep(60)
|
||||
Process.sleep(55)
|
||||
{:ok, "too slow"}
|
||||
end,
|
||||
timeout: 50
|
||||
|
|
@ -67,7 +67,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
|
|||
DeferredDiscovery.slow_check(
|
||||
client_opts,
|
||||
fn ->
|
||||
Process.sleep(60)
|
||||
Process.sleep(55)
|
||||
{:ok, "too slow"}
|
||||
end,
|
||||
timeout: 50,
|
||||
|
|
@ -84,7 +84,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
|
|||
DeferredDiscovery.slow_check(
|
||||
client_opts,
|
||||
fn ->
|
||||
Process.sleep(60)
|
||||
Process.sleep(55)
|
||||
{:ok, "too slow"}
|
||||
end,
|
||||
timeout: 50,
|
||||
|
|
@ -129,7 +129,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
|
|||
DeferredDiscovery.deferred_check(
|
||||
client_opts,
|
||||
fn ->
|
||||
Process.sleep(60)
|
||||
Process.sleep(55)
|
||||
{: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(60)
|
||||
Process.sleep(55)
|
||||
{: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(60)
|
||||
Process.sleep(55)
|
||||
{:ok, [1, 3, 6, 1, 4, 1, 9]}
|
||||
end)
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ defmodule Towerops.Snmp.DeferredDiscoveryTest do
|
|||
test "returns :slow for delayed responses" do
|
||||
expect(SnmpMock, :get, fn _target, _oid, _opts ->
|
||||
# Sleep just past the threshold to be classified as slow
|
||||
Process.sleep(60)
|
||||
Process.sleep(55)
|
||||
{:ok, "Slow Device"}
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ defmodule Towerops.Snmp.SensorChangeDetectorTest do
|
|||
|
||||
SensorChangeDetector.detect_and_broadcast(sensor, 50.0, timestamp)
|
||||
|
||||
refute_receive {:device_event, _}, 100
|
||||
refute_receive {:device_event, _}, 50
|
||||
end
|
||||
|
||||
test "does not emit sensor_value_changed when last_value is nil", %{device: device, snmp_device: snmp_device} do
|
||||
|
|
@ -125,7 +125,7 @@ defmodule Towerops.Snmp.SensorChangeDetectorTest do
|
|||
|
||||
SensorChangeDetector.detect_and_broadcast(sensor, 50.0, timestamp)
|
||||
|
||||
refute_receive {:device_event, _}, 100
|
||||
refute_receive {:device_event, _}, 50
|
||||
end
|
||||
|
||||
test "emits spike event for % sensor with >=30% increase", %{
|
||||
|
|
@ -194,7 +194,7 @@ defmodule Towerops.Snmp.SensorChangeDetectorTest do
|
|||
|
||||
# Should not get spike/drop events for small % changes
|
||||
# (no sensor_value_changed for % sensors either, they use spike/drop)
|
||||
refute_receive {:device_event, _}, 100
|
||||
refute_receive {:device_event, _}, 50
|
||||
end
|
||||
|
||||
test "emits threshold warning event", %{
|
||||
|
|
|
|||
|
|
@ -491,7 +491,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
|
||||
send(socket.channel_pid, :check_heartbeat)
|
||||
|
||||
assert_receive {:DOWN, ^ref, :process, _, _}, 5_000
|
||||
assert_receive {:DOWN, ^ref, :process, _, _}, 1000
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -502,7 +502,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
|
||||
send(socket.channel_pid, :token_disabled)
|
||||
|
||||
assert_receive {:DOWN, ^ref, :process, _, _}, 5_000
|
||||
assert_receive {:DOWN, ^ref, :process, _, _}, 1000
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -514,7 +514,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
send(socket.channel_pid, :restart_requested)
|
||||
|
||||
assert_push "restart", %{}
|
||||
assert_receive {:DOWN, ^ref, :process, _, _}, 5_000
|
||||
assert_receive {:DOWN, ^ref, :process, _, _}, 1000
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -691,7 +691,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
push(socket, "result", encode_payload(discovery_result))
|
||||
|
||||
# Wait for discovery to complete and the automatic poll_after_discovery
|
||||
assert_push "jobs", %{binary: jobs_binary}, 5_000
|
||||
assert_push "jobs", %{binary: jobs_binary}, 1000
|
||||
|
||||
{:ok, decoded_binary} = Base.decode64(jobs_binary)
|
||||
job_list = AgentJobList.decode(decoded_binary)
|
||||
|
|
@ -786,7 +786,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
payload = encode_payload(result)
|
||||
push(socket, "result", payload)
|
||||
|
||||
assert_receive {:live_poll_result, oid_values}, 2_000
|
||||
assert_receive {:live_poll_result, oid_values}, 500
|
||||
assert Map.has_key?(oid_values, "1.3.6.1.2.1.1.1.0")
|
||||
end
|
||||
end
|
||||
|
|
@ -1183,7 +1183,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
push(socket, "result", payload)
|
||||
|
||||
# Should receive a "jobs" push with poll job(s) for the discovered device
|
||||
assert_push "jobs", %{binary: jobs_binary}, 5_000
|
||||
assert_push "jobs", %{binary: jobs_binary}, 1000
|
||||
|
||||
# Decode the job list and verify it contains a POLL job for our device
|
||||
{:ok, decoded_binary} = Base.decode64(jobs_binary)
|
||||
|
|
@ -1240,7 +1240,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
push(socket, "result", payload)
|
||||
|
||||
# Receive the poll job pushed after discovery
|
||||
assert_push "jobs", %{binary: jobs_binary}, 5_000
|
||||
assert_push "jobs", %{binary: jobs_binary}, 1000
|
||||
|
||||
{:ok, decoded_binary} = Base.decode64(jobs_binary)
|
||||
job_list = AgentJobList.decode(decoded_binary)
|
||||
|
|
@ -1276,7 +1276,7 @@ defmodule ToweropsWeb.AgentChannelTest do
|
|||
# Trigger a fresh job push by sending :send_jobs
|
||||
send(socket.channel_pid, :send_jobs)
|
||||
|
||||
assert_push "jobs", %{binary: jobs_binary}, 5_000
|
||||
assert_push "jobs", %{binary: jobs_binary}, 1000
|
||||
|
||||
{:ok, decoded_binary} = Base.decode64(jobs_binary)
|
||||
job_list = AgentJobList.decode(decoded_binary)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue