towerops/lib/towerops
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
..
accounts add user profile settings with name, avatar, and timezone 2026-01-18 10:32:23 -06:00
admin Add superuser system with user impersonation for admin support 2026-01-06 12:50:10 -06:00
agents Add agent rename functionality 2026-01-17 15:48:47 -06:00
alerts moduledocs 2026-01-17 15:08:49 -06:00
api_tokens refactor: use API token auth for profile imports instead of session cookies 2026-01-18 09:30:21 -06:00
devices feat: allow device name to be populated from SNMP sysName 2026-01-17 16:28:43 -06:00
ecto_types improve profile import 2026-01-18 11:46:56 -06:00
mobile_sessions Fix datetime truncation for mobile session schemas 2026-01-15 16:17:05 -06:00
monitoring Fix database connection ownership issues in async Tasks 2026-01-20 12:39:25 -06:00
organizations moduledocs 2026-01-17 15:08:49 -06:00
profiles add universoal import 2026-01-18 16:59:34 -06:00
proto Add ICMP monitoring support to Phoenix agent channel 2026-01-19 13:46:20 -06:00
sites moduledocs 2026-01-17 15:08:49 -06:00
snmp Fix database connection ownership issues in async Tasks 2026-01-20 12:39:25 -06:00
workers Refactor MonitorWorker to use ping adapter and eliminate real network traffic from tests 2026-01-20 12:29:12 -06:00
accounts.ex add user profile settings with name, avatar, and timezone 2026-01-18 10:32:23 -06:00
admin.ex rename equipment to device 2026-01-17 14:48:46 -06:00
agents.ex Add agent rename functionality 2026-01-17 15:48:47 -06:00
alerts.ex rename equipment to device 2026-01-17 14:48:46 -06:00
api_tokens.ex Fix database connection ownership issues in async Tasks 2026-01-20 12:39:25 -06:00
application.ex Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
devices.ex Fix Credo issues and improve code quality 2026-01-19 15:09:19 -06:00
exq_supervisor.ex Add Redix connection resilience options to Exq config 2026-01-20 11:42:02 -06:00
log_filter.ex Add comprehensive Dialyzer type specifications 2026-01-17 10:52:02 -06:00
mailer.ex moduledocs 2026-01-17 15:08:49 -06:00
mobile_sessions.ex credo cleanup 2026-01-17 15:00:52 -06:00
monitoring.ex feat: add latency graph for ICMP ping monitoring 2026-01-17 16:02:35 -06:00
organizations.ex rename equipment to device 2026-01-17 14:48:46 -06:00
profiles.ex add universoal import 2026-01-18 16:59:34 -06:00
redis_health_check.ex Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
release.ex fix dialyzer things 2026-01-03 12:56:40 -06:00
repo.ex moduledocs 2026-01-17 15:08:49 -06:00
sites.ex rename equipment to device 2026-01-17 14:48:46 -06:00
snmp.ex more renames 2026-01-17 15:13:56 -06:00