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.
This commit is contained in:
Graham McIntire 2026-05-10 11:14:47 -05:00
parent 4937570c2a
commit 670516f641
3 changed files with 19 additions and 1 deletions

View file

@ -47,13 +47,28 @@ ExUnit.start()
# aren't installed (e.g. CI test gate runs in a lean image without # 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 # gdal-bin). Locally we install GDAL via `brew install gdal` per
# CLAUDE.md, so the test runs there. # CLAUDE.md, so the test runs there.
extra_excludes = gdal_excludes =
if System.find_executable("gdal_translate") && System.find_executable("gdaldem") do if System.find_executable("gdal_translate") && System.find_executable("gdaldem") do
[] []
else else
[:requires_gdal] [:requires_gdal]
end 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 # Exclude tests by default
# Run specific tests with: mix test --only <tag> # Run specific tests with: mix test --only <tag>
ExUnit.configure( ExUnit.configure(

View file

@ -5,6 +5,8 @@ defmodule Towerops.RedisHealthCheckTest do
alias Towerops.RedisHealthCheck alias Towerops.RedisHealthCheck
@moduletag :requires_redis
describe "wait_for_redis/2" do describe "wait_for_redis/2" do
test "returns :ok when Redis is available" do test "returns :ok when Redis is available" do
redis_config = Application.get_env(:towerops, :redis, host: "localhost", port: 6379) redis_config = Application.get_env(:towerops, :redis, host: "localhost", port: 6379)

View file

@ -4,6 +4,7 @@ defmodule Towerops.Security.FourOhFourTrackerTest do
alias Towerops.Security.FourOhFourTracker alias Towerops.Security.FourOhFourTracker
@moduletag :four_oh_four_tracker @moduletag :four_oh_four_tracker
@moduletag :requires_redis
setup do setup do
# Ensure a real Redix connection exists for these tests. # Ensure a real Redix connection exists for these tests.