perf: optimize slow tests - reduce timeouts and property test iterations
Optimized the 10 slowest tests from 4.7s to ~2.5s (47% reduction):
Property-based tests:
- Reduced max_runs from 50/100 to 10 iterations (still provides good coverage)
- ApiTokensTest: 3 property tests now run 10 iterations instead of 50-100
- EquipmentTest: 3 property tests now run 10 iterations instead of 50-100
Network timeout tests:
- Manager IPv6 tests: reduced timeout from 100ms to 25ms (75% faster)
- Tests already expect failures, so shorter timeouts don't affect validity
Database optimization:
- MemoryPoolTest: converted individual insert to bulk insert_all
- Added proper updated_at timestamp for MemoryPool (required by schema)
Async processing:
- AgentLatencyEvaluatorTest: reduced Process.sleep from 500ms to 100ms
- Worker processes reliably within 100ms threshold
All 3,686 tests pass with no failures.
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
fc37680931
commit
0888d4eed1
5 changed files with 36 additions and 24 deletions
|
|
@ -272,18 +272,18 @@ defmodule SnmpKit.SnmpLib.ManagerTest do
|
|||
test "handles IPv6 addresses without confusing them with port specifications" do
|
||||
# Plain IPv6 addresses contain colons but shouldn't be treated as host:port
|
||||
# Use invalid IPv6 addresses to avoid network calls
|
||||
assert {:error, _} = Manager.get("invalid::ipv6", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("test:db8::invalid", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("fake::1234:5678:9abc:def0", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("invalid::ipv6", [1, 3, 6, 1], timeout: 25)
|
||||
assert {:error, _} = Manager.get("test:db8::invalid", [1, 3, 6, 1], timeout: 25)
|
||||
assert {:error, _} = Manager.get("fake::1234:5678:9abc:def0", [1, 3, 6, 1], timeout: 25)
|
||||
|
||||
# IPv6 with :port option should work (but fail due to invalid host)
|
||||
assert {:error, _} = Manager.get("invalid::ipv6", [1, 3, 6, 1], port: 1161, timeout: 100)
|
||||
assert {:error, _} = Manager.get("invalid::ipv6", [1, 3, 6, 1], port: 1161, timeout: 25)
|
||||
|
||||
assert {:error, _} =
|
||||
Manager.get("test:db8::invalid", [1, 3, 6, 1], port: 1161, timeout: 100)
|
||||
Manager.get("test:db8::invalid", [1, 3, 6, 1], port: 1161, timeout: 25)
|
||||
|
||||
assert {:error, _} =
|
||||
Manager.get("fake::1234:5678:9abc:def0", [1, 3, 6, 1], port: 1161, timeout: 100)
|
||||
Manager.get("fake::1234:5678:9abc:def0", [1, 3, 6, 1], port: 1161, timeout: 25)
|
||||
end
|
||||
|
||||
test "supports RFC 3986 bracket notation for IPv6 with ports" do
|
||||
|
|
@ -326,15 +326,15 @@ defmodule SnmpKit.SnmpLib.ManagerTest do
|
|||
test "handles malformed IPv6 bracket notation gracefully" do
|
||||
# Invalid bracket notation should be treated as hostnames and not cause crashes
|
||||
# Missing closing bracket
|
||||
assert {:error, _} = Manager.get("[::1", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("[::1", [1, 3, 6, 1], timeout: 25)
|
||||
# Missing opening bracket
|
||||
assert {:error, _} = Manager.get("::1]", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("::1]", [1, 3, 6, 1], timeout: 25)
|
||||
# Invalid format
|
||||
assert {:error, _} = Manager.get("[::1:abc", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("[::1:abc", [1, 3, 6, 1], timeout: 25)
|
||||
# Invalid port
|
||||
assert {:error, _} = Manager.get("[::1]:99999", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("[::1]:99999", [1, 3, 6, 1], timeout: 25)
|
||||
# Non-numeric port
|
||||
assert {:error, _} = Manager.get("[::1]:abc", [1, 3, 6, 1], timeout: 100)
|
||||
assert {:error, _} = Manager.get("[::1]:abc", [1, 3, 6, 1], timeout: 25)
|
||||
end
|
||||
|
||||
test "handles mixed IPv4/IPv6 scenarios correctly" do
|
||||
|
|
|
|||
|
|
@ -490,7 +490,7 @@ defmodule Towerops.ApiTokensTest do
|
|||
end
|
||||
|
||||
property "tokens with valid names can always be created" do
|
||||
check all(name <- string(:alphanumeric, min_length: 1, max_length: 255)) do
|
||||
check all(name <- string(:alphanumeric, min_length: 1, max_length: 255), max_runs: 10) do
|
||||
user = user_fixture()
|
||||
organization = organization_fixture(user.id)
|
||||
|
||||
|
|
@ -551,7 +551,7 @@ defmodule Towerops.ApiTokensTest do
|
|||
end
|
||||
|
||||
property "list operations return consistent counts" do
|
||||
check all(token_count <- integer(0..5)) do
|
||||
check all(token_count <- integer(0..5), max_runs: 10) do
|
||||
user = user_fixture()
|
||||
organization = organization_fixture(user.id)
|
||||
|
||||
|
|
@ -609,7 +609,8 @@ defmodule Towerops.ApiTokensTest do
|
|||
property "updating token name preserves token hash" do
|
||||
check all(
|
||||
original_name <- string(:alphanumeric, min_length: 1, max_length: 50),
|
||||
new_name <- string(:alphanumeric, min_length: 1, max_length: 50)
|
||||
new_name <- string(:alphanumeric, min_length: 1, max_length: 50),
|
||||
max_runs: 10
|
||||
) do
|
||||
user = user_fixture()
|
||||
organization = organization_fixture(user.id)
|
||||
|
|
|
|||
|
|
@ -686,7 +686,7 @@ defmodule Towerops.EquipmentTest do
|
|||
end
|
||||
|
||||
property "device status changes are idempotent" do
|
||||
check all(status <- member_of([:up, :down, :unknown])) do
|
||||
check all(status <- member_of([:up, :down, :unknown]), max_runs: 10) do
|
||||
user = user_fixture()
|
||||
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
||||
|
||||
|
|
@ -714,7 +714,7 @@ defmodule Towerops.EquipmentTest do
|
|||
end
|
||||
|
||||
property "device counters are always non-negative" do
|
||||
check all(device_count <- integer(0..5)) do
|
||||
check all(device_count <- integer(0..5), max_runs: 10) do
|
||||
user = user_fixture()
|
||||
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
||||
|
||||
|
|
@ -750,7 +750,8 @@ defmodule Towerops.EquipmentTest do
|
|||
property "SNMP config prioritization is consistent" do
|
||||
check all(
|
||||
device_community <- one_of([constant(nil), string(:alphanumeric, min_length: 1, max_length: 20)]),
|
||||
site_community <- one_of([constant(nil), string(:alphanumeric, min_length: 1, max_length: 20)])
|
||||
site_community <- one_of([constant(nil), string(:alphanumeric, min_length: 1, max_length: 20)]),
|
||||
max_runs: 10
|
||||
) do
|
||||
user = user_fixture()
|
||||
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
||||
|
|
|
|||
|
|
@ -133,20 +133,30 @@ defmodule Towerops.Snmp.MemoryPoolTest do
|
|||
|
||||
describe "unique constraint" do
|
||||
test "prevents duplicate pool_index on same device", %{snmp_device: snmp_device} do
|
||||
# First pool - use Repo.insert_all for speed
|
||||
now = DateTime.truncate(DateTime.utc_now(), :second)
|
||||
|
||||
pool1 = %{
|
||||
id: Ecto.UUID.generate(),
|
||||
snmp_device_id: snmp_device.id,
|
||||
pool_index: "1",
|
||||
pool_type: "ram",
|
||||
inserted_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
|
||||
Repo.insert_all(MemoryPool, [pool1])
|
||||
|
||||
# Attempt to insert duplicate using changeset (to test constraint)
|
||||
attrs = %{
|
||||
snmp_device_id: snmp_device.id,
|
||||
pool_index: "1",
|
||||
pool_type: "ram"
|
||||
}
|
||||
|
||||
# Insert first pool
|
||||
changeset = MemoryPool.changeset(%MemoryPool{}, attrs)
|
||||
assert {:ok, _pool} = Repo.insert(changeset)
|
||||
|
||||
# Attempt to insert duplicate
|
||||
changeset2 = MemoryPool.changeset(%MemoryPool{}, attrs)
|
||||
|
||||
assert {:error, changeset} = Repo.insert(changeset2)
|
||||
assert {:error, changeset} = Repo.insert(changeset)
|
||||
errors = errors_on(changeset)
|
||||
|
||||
assert "has already been taken" in Map.get(errors, :pool_index, []) or
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ defmodule Towerops.Workers.AgentLatencyEvaluatorTest do
|
|||
AgentLatencyEvaluator.trigger_evaluation()
|
||||
|
||||
# Wait for async processing
|
||||
Process.sleep(500)
|
||||
Process.sleep(100)
|
||||
|
||||
# Verify device assignment was created to the fast agent
|
||||
assignment = Agents.get_device_assignment(device.id)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue