diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 8f5aaf4..53f29cc 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -37,9 +37,25 @@ jobs: otp-version: ${{matrix.pair.otp}} elixir-version: ${{matrix.pair.elixir}} + # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones + # Cache key based on Elixir & Erlang version (also useful when running in matrix) + - name: Cache Dialyzer's PLT + uses: actions/cache@v3 + if: ${{ matrix.lint }} + id: cache-plt + with: + path: _build/test + key: | + ${{ runner.os }}-plt-otp${{ matrix.erlang }}-elixir${{ matrix.elixir }} + - name: Install Dependencies run: mix deps.get + # Create PLTs if no cache was found + - name: Create PLTs + if: ${{ matrix.lint && steps.cache-plt.outputs.cache-hit != 'true' }} + run: mix dialyzer --plt + - run: mix format --check-formatted if: ${{ matrix.lint }} @@ -62,3 +78,7 @@ jobs: - name: Run Tests run: mix test --warnings-as-errors if: ${{ matrix.lint }} + + - name: Run Dialyzer + run: mix dialyzer + if: ${{ matrix.lint }} diff --git a/lib/finch/http1/pool_metrics.ex b/lib/finch/http1/pool_metrics.ex index 32c9945..fb7d552 100644 --- a/lib/finch/http1/pool_metrics.ex +++ b/lib/finch/http1/pool_metrics.ex @@ -45,7 +45,7 @@ defmodule Finch.HTTP1.PoolMetrics do def maybe_add(nil, _metrics_list), do: :ok - def maybe_add(ref, metrics_list) when is_reference(ref) do + def maybe_add(ref, metrics_list) do Enum.each(metrics_list, fn {metric_name, val} -> :atomics.add(ref, @atomic_idx[metric_name], val) end) @@ -57,7 +57,9 @@ defmodule Finch.HTTP1.PoolMetrics do |> get_pool_status() end - def get_pool_status(ref) when is_reference(ref) do + def get_pool_status(nil), do: {:error, :not_found} + + def get_pool_status(ref) do %{ pool_idx: pool_idx, pool_size: pool_size, @@ -76,6 +78,4 @@ defmodule Finch.HTTP1.PoolMetrics do {:ok, result} end - - def get_pool_status(nil), do: {:error, :not_found} end diff --git a/lib/finch/http2/pool_metrics.ex b/lib/finch/http2/pool_metrics.ex index 9224bf0..b7c59a6 100644 --- a/lib/finch/http2/pool_metrics.ex +++ b/lib/finch/http2/pool_metrics.ex @@ -35,7 +35,7 @@ defmodule Finch.HTTP2.PoolMetrics do def maybe_add(nil, _metrics_list), do: :ok - def maybe_add(ref, metrics_list) when is_reference(ref) do + def maybe_add(ref, metrics_list) do Enum.each(metrics_list, fn {metric_name, val} -> :atomics.add(ref, @atomic_idx[metric_name], val) end) @@ -47,7 +47,9 @@ defmodule Finch.HTTP2.PoolMetrics do |> get_pool_status() end - def get_pool_status(ref) when is_reference(ref) do + def get_pool_status(nil), do: {:error, :not_found} + + def get_pool_status(ref) do %{ pool_idx: pool_idx, in_flight_requests: in_flight_requests @@ -63,6 +65,4 @@ defmodule Finch.HTTP2.PoolMetrics do {:ok, result} end - - def get_pool_status(nil), do: {:error, :not_found} end