Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Sep 9, 2024
1 parent 7c2a84b commit b201e15
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,42 @@ on:
jobs:
test:
name: Test (Elixir ${{matrix.elixir}} | Erlang/OTP ${{matrix.otp}})
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- otp: "27.0"
elixir: "1.17.0"
version-type: strict
elixir: "1.17"
os: ubuntu-latest
dialyzer: true
lint: true

- otp: "25.3"
elixir: "1.14.3"
os: ubuntu-20.04
coverage: true
version-type: loose

- otp: "23.0"
elixir: "1.12"
version-type: loose
os: ubuntu-20.04

env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MIX_ENV: test

steps:
- name: Clone the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Start Docker
run: docker compose up --detach

- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
version-type: ${{matrix.version-type}}
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}

- name: Cache dependencies
id: cache-deps
Expand Down
20 changes: 17 additions & 3 deletions lib/redix/connector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@ defmodule Redix.Connector do
Logger.debug(fn ->
"Sentinel reported #{sentinel_opts[:role]}: #{server_host}:#{server_port}"
end),
{:ok, server_socket, _address} <-
server_host = string_address_to_erlang(server_host),
{:ok, server_socket, address} <-
connect_directly(
String.to_charlist(server_host),
server_host,
String.to_integer(server_port),
opts
),
:ok <- verify_server_role(server_socket, opts, sentinel_opts) do
:ok = transport.close(sent_socket)
{:ok, server_socket, "#{server_host}:#{server_port}"}
{:ok, server_socket, address}
else
{cause, reason} when cause in [:error, :stop] ->
:telemetry.execute([:redix, :failed_connection], %{}, %{
Expand All @@ -171,6 +172,19 @@ defmodule Redix.Connector do
end
end

defp string_address_to_erlang(address) when is_binary(address) do
address = String.to_charlist(address)

case :inet.parse_address(address) do
{:ok, ip} -> ip
{:error, :einval} -> address
end
end

defp string_address_to_erlang(address) do
address
end

defp connect_to_sentinel(sentinel, sentinel_opts, transport) do
host = Keyword.fetch!(sentinel, :host)
port = Keyword.fetch!(sentinel, :port)
Expand Down
10 changes: 10 additions & 0 deletions lib/redix/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ defmodule Redix.Format do

def format_host_and_port(host, port) when is_list(host),
do: format_host_and_port(IO.chardata_to_string(host), port)

def format_host_and_port(host, port) when is_tuple(host) do
case :inet.ntoa(host) do
{:error, :einval} ->
raise ArgumentError, "invalid host: #{inspect(host)}"

host ->
format_host_and_port(host, port)

Check warning on line 24 in lib/redix/format.ex

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.17 | Erlang/OTP 27.0)

call

The function call format_host_and_port will not succeed.
end
end
end
1 change: 1 addition & 0 deletions test/redix/sentinel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule Redix.SentinelTest do
assert_receive {:redix_pubsub, ^pubsub, ^ref, :message, %{channel: "foo", payload: "hello"}}
end

@tag :capture_log
test "when no sentinels are reachable" do
Process.flag(:trap_exit, true)

Expand Down

0 comments on commit b201e15

Please sign in to comment.