From 670516f6417f64b8edbab86a4b1c49a4acdde6c5 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 10 May 2026 11:14:47 -0500 Subject: [PATCH] test: skip Redis-dependent tests in CI when Redis isn't reachable The Forgejo CI test gate has no Redis service, so FourOhFourTracker and RedisHealthCheck tests fail with Redix.ConnectionError. They've always been broken in CI but the failures got noticed now. Mirrors the existing :requires_gdal pattern: probe localhost:6379 in test_helper.exs and add :requires_redis to extra_excludes when nothing answers. Locally (where direnv runs Redis) the tag isn't excluded so the tests still run. --- test/test_helper.exs | 17 ++++++++++++++++- test/towerops/redis_health_check_test.exs | 2 ++ .../security/four_oh_four_tracker_test.exs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/test_helper.exs b/test/test_helper.exs index 9d0245ec..27abfc49 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -47,13 +47,28 @@ ExUnit.start() # aren't installed (e.g. CI test gate runs in a lean image without # gdal-bin). Locally we install GDAL via `brew install gdal` per # CLAUDE.md, so the test runs there. -extra_excludes = +gdal_excludes = if System.find_executable("gdal_translate") && System.find_executable("gdaldem") do [] else [:requires_gdal] end +# Skip Redis-backed tests when Redis isn't reachable on localhost:6379 +# (e.g. the Forgejo CI test gate has no Redis service). Local dev runs +# Redis via direnv/services so the tests run there. +redis_excludes = + case :gen_tcp.connect(~c"127.0.0.1", 6379, [:binary, active: false], 250) do + {:ok, sock} -> + :gen_tcp.close(sock) + [] + + {:error, _} -> + [:requires_redis] + end + +extra_excludes = gdal_excludes ++ redis_excludes + # Exclude tests by default # Run specific tests with: mix test --only ExUnit.configure( diff --git a/test/towerops/redis_health_check_test.exs b/test/towerops/redis_health_check_test.exs index 82f26597..743d3d8e 100644 --- a/test/towerops/redis_health_check_test.exs +++ b/test/towerops/redis_health_check_test.exs @@ -5,6 +5,8 @@ defmodule Towerops.RedisHealthCheckTest do alias Towerops.RedisHealthCheck + @moduletag :requires_redis + describe "wait_for_redis/2" do test "returns :ok when Redis is available" do redis_config = Application.get_env(:towerops, :redis, host: "localhost", port: 6379) diff --git a/test/towerops/security/four_oh_four_tracker_test.exs b/test/towerops/security/four_oh_four_tracker_test.exs index e707cb42..07a9b36c 100644 --- a/test/towerops/security/four_oh_four_tracker_test.exs +++ b/test/towerops/security/four_oh_four_tracker_test.exs @@ -4,6 +4,7 @@ defmodule Towerops.Security.FourOhFourTrackerTest do alias Towerops.Security.FourOhFourTracker @moduletag :four_oh_four_tracker + @moduletag :requires_redis setup do # Ensure a real Redix connection exists for these tests.