towerops/lib/towerops/snmp
Graham McIntire ace3f1f661
Fix database connection ownership issues in async Tasks
Changes:
- ApiTokens.update_last_used/1: Allow Task to access sandbox in tests
- DeviceMonitor.enqueue_check/1: Allow Task to access sandbox in tests
- PollerWorker.enqueue_poll/1: Allow Task to access sandbox in tests

Problem:
When tests spawn async Tasks that access the database, those Tasks
don't have ownership of the database connection in Sandbox mode,
causing DBConnection.ConnectionError warnings.

Solution:
Before accessing the database in a Task, check if we're in test mode
and call Ecto.Adapters.SQL.Sandbox.allow/3 to transfer connection
ownership from the parent process to the Task.

Pattern used:
```elixir
parent = self()
Task.start(fn ->
  if Application.get_env(:towerops, :sql_sandbox) do
    Ecto.Adapters.SQL.Sandbox.allow(Repo, parent, self())
  end
  # ... database operations ...
end)
```

All 1041 tests passing. Some harmless disconnection warnings remain
when Tasks complete after tests finish, but these don't affect results.
2026-01-20 12:39:25 -06:00
..
profiles test improvements 2026-01-19 12:08:48 -06:00
client.ex fix device identification 2026-01-18 13:35:33 -06:00
device.ex test improvements 2026-01-19 12:08:48 -06:00
discovery.ex test improvements 2026-01-19 12:08:48 -06:00
interface.ex moduledocs 2026-01-17 15:08:49 -06:00
interface_stat.ex moduledocs 2026-01-17 15:08:49 -06:00
mib_parser.ex add MIB-based validation and generic profile tests 2026-01-08 08:57:21 -06:00
mib_translator.ex Auto-expand MIB directories to include subdirectories 2026-01-19 14:06:51 -06:00
neighbor.ex moduledocs 2026-01-17 15:08:49 -06:00
neighbor_cleanup_worker.ex rename equipment to device 2026-01-17 14:48:46 -06:00
neighbor_discovery.ex rename equipment to device 2026-01-17 14:48:46 -06:00
poller.ex snmp overhaul 2026-01-18 16:00:01 -06:00
poller_behaviour.ex snmp bits 2026-01-03 14:41:28 -06:00
poller_worker.ex Fix database connection ownership issues in async Tasks 2026-01-20 12:39:25 -06:00
sensor.ex moduledocs 2026-01-17 15:08:49 -06:00
sensor_reading.ex Fix all remaining worker test failures 2026-01-20 12:20:04 -06:00
snmp_behaviour.ex moar tests 2026-01-06 15:43:54 -06:00