towerops/test/towerops_web/live/admin/dashboard_live_test.exs
Graham McIntire 74e7a8b774
perf: optimize test suite and CI pipeline for maximum speed
Test Suite Optimizations:
- Fix property-based test max_runs config (6s → 10ms, 99.9% faster)
- Replace Process.sleep with DateTime manipulation in timestamp tests
  (5 tests × 1s → 10ms each, eliminating 5.5s of sleep time)
- Reduce agent channel test timeouts (1000ms → 800ms)
- Reuse fixtures in admin dashboard tests
- Result: Top 10 slowest tests reduced from 16.0s to 8.1s (50% faster)

CI Pipeline Optimizations:
- Restructure to compile-first architecture with artifact sharing
- Add parallel execution: quality checks (format + credo) run concurrently
- Enhance caching: Hex/Mix, Rust/Cargo, system deps, build artifacts
- Optimize dependency installation with conditional steps
- Improve PostgreSQL health checks and wait loops
- Result: 20-30% faster cold runs, 50-60% faster warm runs (estimated)

Architecture changes:
- Before: Single sequential job (format → compile → credo → test)
- After: Parallel pipeline (compile → [quality | test] → build)

Cache improvements:
- Add ~/.hex and ~/.mix caching
- Add Rust/Cargo target caching for Rustler NIF
- Include Rust source hashes in cache keys
- Skip apt-get update on cache hit
- Use --no-install-recommends for faster installs
2026-03-05 15:04:57 -06:00

52 lines
1.5 KiB
Elixir

defmodule ToweropsWeb.Admin.DashboardLiveTest do
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
setup do
user = Towerops.AccountsFixtures.user_fixture()
user = user |> Ecto.Changeset.change(%{is_superuser: true}) |> Towerops.Repo.update!()
{:ok, _organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
token = Towerops.Accounts.generate_user_session_token(user)
conn =
build_conn()
|> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:user_token, token)
%{conn: conn, user: user}
end
describe "mount" do
test "renders admin dashboard for superuser", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ "Admin Dashboard"
end
test "shows user and org counts", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ "Users"
assert html =~ "Organizations"
end
test "redirects non-superuser to /orgs", %{user: user} do
# Use existing user from setup but remove superuser flag
regular_user =
user
|> Ecto.Changeset.change(%{is_superuser: false})
|> Towerops.Repo.update!()
token = Towerops.Accounts.generate_user_session_token(regular_user)
conn =
build_conn()
|> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:user_token, token)
assert {:error, {:redirect, %{to: "/orgs"}}} = live(conn, ~p"/admin")
end
end
end