# Reduce parallelism when coverage is enabled to prevent file descriptor exhaustion
# Reduced from System.schedulers_online() * 4 to avoid trigger-based
# packet counter deadlocks under concurrent insert/delete workloads.
# The packet counter trigger serializes on a single row; high parallelism
# creates contention with no throughput benefit for insert-heavy tests.
max_cases =
  if System.get_env("MIX_TEST_COVERAGE") do
    2
  else
    4
  end

ExUnit.start(
  max_cases: max_cases,
  timeout: 30_000,
  capture_log: true,
  exclude: [:integration]
)

Ecto.Adapters.SQL.Sandbox.mode(Aprsme.Repo, :manual)

# Configure Mox
Mox.defmock(Aprsme.PacketsMock, for: Aprsme.PacketsBehaviour)
Mox.defmock(PacketsMock, for: Aprsme.PacketsBehaviour)

# Set up default stubs for commonly used functions
Mox.stub(Aprsme.PacketsMock, :get_recent_packets, fn _opts -> [] end)
Mox.stub(Aprsme.PacketsMock, :get_nearby_stations, fn _lat, _lon, _exclude, _opts -> [] end)

# Ensure no external APRS connections during tests
Application.put_env(:aprsme, :aprs_is_server, "mock.aprs.test")
Application.put_env(:aprsme, :packets_module, Aprsme.PacketsMock)

# AprsIsMock is automatically loaded from test/support via elixirc_paths
