From 09e5ffc6bcd55bc0ab0d35bcf090f7a5cef60583 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Sun, 9 Nov 2025 20:41:19 +0000 Subject: [PATCH 01/15] Remove Circle CI and move to Github Actions --- .circleci/config.yml | 144 --------------------------------------- .github/workflows/ci.yml | 94 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 144 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/ci.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index a826375..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,144 +0,0 @@ -version: 2.1 - -jobs: - build: - docker: - - image: cimg/elixir:1.15.5-erlang-26.0.2 - environment: - MIX_ENV: test - steps: - - checkout - - run: - name: Install tools - command: | - mix local.hex --force && \ - mix local.rebar --force - - restore_cache: - keys: - - v2-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }} - - v2-mix-cache-{{ .Branch }} - - v2-mix-cache - - run: - name: Get dependencies - command: mix deps.get - - save_cache: - key: v2-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }} - paths: - - deps - - restore_cache: - keys: - - v4-build-cache-{{ .Branch }} - - v4-build-cache - - run: - name: Compile - command: mix do deps.compile, compile --warnings-as-errors, dialyzer --plt - - save_cache: - key: v4-build-cache-{{ .Branch }} - paths: - - _build - - persist_to_workspace: - root: ~/ - paths: - - .mix - - project/_build - - project/deps - - test: - docker: - - image: cimg/elixir:1.15.5-erlang-26.0.2 - environment: - MIX_ENV: test - - image: cimg/postgres:14.6 - steps: - - checkout - - attach_workspace: - at: ~/ - - run: - name: Run tests - command: mix test --cover --export-coverage default - - run: - name: Check coverage - command: mix test.coverage - - store_test_results: - path: /tmp/test/results.xml - - lint: - docker: - - image: cimg/elixir:1.15.5-erlang-26.0.2 - environment: - MIX_ENV: test - steps: - - checkout - - attach_workspace: - at: ~/ - - run: - name: Check formatting - command: mix format --check-formatted --dry-run - - run: - name: Check for retired dependencies - command: mix hex.audit - - run: - name: Check unused dependencies - command: mix deps.unlock --check-unused - - run: - name: Check outdated dependencies - command: mix hex.outdated --within-requirements || true - - run: - name: Credo - command: mix credo --all - - run: - name: Dialyzer - command: mix dialyzer - - run: - name: Check documentation - command: mix doctor - - security: - docker: - - image: cimg/elixir:1.15.5-erlang-26.0.2 - environment: - MIX_ENV: test - steps: - - checkout - - attach_workspace: - at: ~/ - - run: - name: Audit dependencies - command: mix deps.audit - - run: - name: Sobelow - command: mix sobelow --config - - slscan: - docker: - - image: shiftleft/sast-scan:maven385 - environment: - FETCH_LICENSE: "true" - working_directory: /tmp/shiftleft-scan - steps: - - checkout - - run: - name: Scan - command: scan --no-error - - store_artifacts: - path: reports - destination: sast-scan-reports - -workflows: - test: - jobs: - - build - - test: - requires: - - build - - lint: - requires: - - build - - security: - requires: - - build - - slscan: - filters: - branches: - only: - - master diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a90b9fe --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,94 @@ +name: Test +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + test: + name: Test (Elixir ${{ matrix.elixir }} | OTP ${{ matrix.otp }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - elixir: 1.17.x + otp: 27 + os: ubuntu-22.04 + - elixir: 1.18.x + otp: 27 + os: ubuntu-22.04 + - elixir: 1.19.x + otp: 28 + os: ubuntu-22.04 + env: + MIX_ENV: test + steps: + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache dependencies + uses: actions/cache@v4 + id: cache-deps + with: + path: | + deps + _build + key: | + mix-${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + mix-${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}- + - name: Install dependencies + run: mix deps.get + + - name: Compile + run: mix compile + + - name: Check for unused packages + run: mix deps.unlock --check-unused + + - run: mix format --check-formatted + + - run: mix credo --strict + + - run: mix dialyzer + + - name: Check for abandonded packages + run: mix hex.audit + + - name: Check outdated dependencies + run: mix hex.outdated --within-requirements || true + + - name: Check for vulnerable packages + run: mix hex.audit + + - name: Run tests + run: mix test + + - name: Run tests (with coverage) + run: mix test --cover --export-coverage default + + - name: Scan for security vulnerabilities + run: mix sobelow --exit --threshold medium + + publish: + name: Publish + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + elixir-version: 1.18 + otp-version: 27 + - name: Fetch dependencies + run: mix deps.get + - name: Compile + run: mix compile + - name: Publish package (Dry Run) + run: mix hex.publish --dry-run --replace --yes From e3488327730f54fe7d6d2107ae228a2ef30f61eb Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Sun, 9 Nov 2025 20:44:47 +0000 Subject: [PATCH 02/15] Include master --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a90b9fe..f13aea8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,9 @@ name: Test on: push: - branches: [main] + branches: [main,master] pull_request: - branches: [main] + branches: [main,master] jobs: test: name: Test (Elixir ${{ matrix.elixir }} | OTP ${{ matrix.otp }}) From 83fa7f931e4608b5299d119fd514dfe4fb87ac0d Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Sun, 9 Nov 2025 20:46:08 +0000 Subject: [PATCH 03/15] Rename Pipelines to CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f13aea8..c0e2232 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Test +name: CI on: push: branches: [main,master] From a9a6bf23e3ba6bcb6ac6752d4f06d2f09e3eadc1 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Sun, 9 Nov 2025 20:50:16 +0000 Subject: [PATCH 04/15] Authorise publish --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0e2232..a4ca890 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: run: mix sobelow --exit --threshold medium publish: - name: Publish + name: Publish (Dry Run) runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -90,5 +90,7 @@ jobs: run: mix deps.get - name: Compile run: mix compile - - name: Publish package (Dry Run) - run: mix hex.publish --dry-run --replace --yes + - name: Publish package + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} + run: mix hex.publish --organization ${{ vars.HEX_ORG }} --dry-run --replace --yes From e2895fedc617dcb598f10805e997ab444fa4b6dc Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Sun, 9 Nov 2025 21:04:04 +0000 Subject: [PATCH 05/15] Fix test fo Elixir 1.19 OTP 28 --- test/zexbox/metrics/metric_handler_test.exs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/zexbox/metrics/metric_handler_test.exs b/test/zexbox/metrics/metric_handler_test.exs index 3844c83..e489bef 100644 --- a/test/zexbox/metrics/metric_handler_test.exs +++ b/test/zexbox/metrics/metric_handler_test.exs @@ -94,10 +94,12 @@ defmodule Zexbox.Metrics.MetricHandlerTest do end test "captures and logs any exceptions", %{event: event, metadata: metadata} do - assert capture_log(fn -> - MetricHandler.handle_event(event, nil, metadata, nil) - end) =~ - "Exception creating controller series: %KeyError" + log = capture_log(fn -> + MetricHandler.handle_event(event, nil, metadata, nil) + end) + + assert log =~ "Exception creating controller series:" and + (log =~ "KeyError" or log =~ "BadMapError") end end end From 878ba8cb7811bce6d3a1bbac2777e521d7c08400 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Sun, 9 Nov 2025 21:05:28 +0000 Subject: [PATCH 06/15] Update metric_handler_test.exs --- test/zexbox/metrics/metric_handler_test.exs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/zexbox/metrics/metric_handler_test.exs b/test/zexbox/metrics/metric_handler_test.exs index e489bef..94d7840 100644 --- a/test/zexbox/metrics/metric_handler_test.exs +++ b/test/zexbox/metrics/metric_handler_test.exs @@ -94,12 +94,9 @@ defmodule Zexbox.Metrics.MetricHandlerTest do end test "captures and logs any exceptions", %{event: event, metadata: metadata} do - log = capture_log(fn -> - MetricHandler.handle_event(event, nil, metadata, nil) - end) - - assert log =~ "Exception creating controller series:" and - (log =~ "KeyError" or log =~ "BadMapError") + assert capture_log(fn -> + MetricHandler.handle_event(event, nil, metadata, nil) + end) =~ "Exception creating controller series: %BadMapError" end end end From 5ae055eaefd9d4d8b9742ad0e169bbf07e79132e Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 11:46:30 +0000 Subject: [PATCH 07/15] Update README --- README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 888a8e6..7b01eab 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Zexbox [![Hex.pm](https://img.shields.io/hexpm/v/zexbox.svg)](https://hex.pm/packages/zexbox) -[![CircleCI](https://dl.circleci.com/status-badge/img/gh/Intellection/zexbox/tree/master.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/gh/Intellection/zexbox/tree/master) +[![CI](https://github.com/Intellection/zexbox/actions/workflows/ci.yml/badge.svg)](https://github.com/Intellection/zexbox/actions/workflows/ci.yml) [![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/zexbox/api-reference.html) ## Installation @@ -16,6 +16,8 @@ end ## LaunchDarkly Feature Flags +The Zexbox library provides an idiomatic Elixir wrapper around the LaunchDarkly Erlang SDK with support for contexts, multi-contexts, and all modern LaunchDarkly features. + ### Configuration Configuration is fairly simple, with the only required piece of configuration being the `sdk_key`. For production environments we recommend also including `:email` as a private attribute: @@ -80,7 +82,35 @@ end Stopping a client with a custom tag can be done using the `Zexbox.Flags.stop/1` function. -Evaluating a flag can be achieved by simply calling the `Zexbox.Flags.variation/3` function. +### Using Contexts + +Contexts are the recommended way to evaluate feature flags. They provide type safety and support for multi-entity targeting: + +```elixir +alias Zexbox.Flags.Context + +# Simple user context +context = Context.new("user-123") +Zexbox.Flags.variation("my-flag", context, false) + +# Context with attributes +context = + Context.new("user-123") + |> Context.set("email", "user@example.com") + |> Context.set("plan", "enterprise") + |> Context.set_private_attributes(["email"]) + +Zexbox.Flags.variation("premium-feature", context, false) + +# Multi-context (target based on user AND organization) +user = Context.new("user-123", "user") +org = Context.new("org-456", "organization") +multi = Context.new_multi([user, org]) + +Zexbox.Flags.variation("enterprise-feature", multi, false) +``` + +**Backward Compatibility**: Raw maps are still supported: ```elixir Zexbox.Flags.variation( @@ -90,6 +120,8 @@ Zexbox.Flags.variation( ) ``` +For more details, see the [Context Module Guide](CONTEXT_MODULE_GUIDE.md). + ## Logging Default logging can be attached to your controllers by calling `Zexbox.Logging.attach_controller_logs!` in the `start/2` function of your `Application` module: From c6b54967c59d2f2bb72d23bc146992405661bfaf Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 11:46:41 +0000 Subject: [PATCH 08/15] Test fix --- test/zexbox/metrics/metric_handler_test.exs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/zexbox/metrics/metric_handler_test.exs b/test/zexbox/metrics/metric_handler_test.exs index 28f91bc..c58f47e 100644 --- a/test/zexbox/metrics/metric_handler_test.exs +++ b/test/zexbox/metrics/metric_handler_test.exs @@ -100,9 +100,11 @@ defmodule Zexbox.Metrics.MetricHandlerTest do end test "captures and logs any exceptions", %{event: event, metadata: metadata} do - assert capture_log(fn -> - MetricHandler.handle_event(event, nil, metadata, nil) - end) =~ "Exception creating controller series: %BadMapError" + log = capture_log(fn -> + MetricHandler.handle_event(event, nil, metadata, nil) + end) + + assert log =~ "Exception creating controller series:" end test "does not call Connection.write when process has disabled metrics", %{ From acaf175d5a6c70dda60c30a8a017968355b98bf7 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 12:10:22 +0000 Subject: [PATCH 09/15] Formatting --- lib/zexbox/metrics.ex | 1 + test/zexbox/metrics/client_test.exs | 6 ++++-- test/zexbox/metrics/context_registry_test.exs | 1 - test/zexbox/metrics/context_test.exs | 1 - test/zexbox/metrics/metric_handler_test.exs | 9 +++++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/zexbox/metrics.ex b/lib/zexbox/metrics.ex index 20c5d58..8006c01 100644 --- a/lib/zexbox/metrics.ex +++ b/lib/zexbox/metrics.ex @@ -37,6 +37,7 @@ defmodule Zexbox.Metrics do Zexbox.Metrics.ContextRegistry, Zexbox.Metrics.Connection ] + Supervisor.init(children, strategy: :one_for_one) end diff --git a/test/zexbox/metrics/client_test.exs b/test/zexbox/metrics/client_test.exs index ce6e4ae..cdfb201 100644 --- a/test/zexbox/metrics/client_test.exs +++ b/test/zexbox/metrics/client_test.exs @@ -38,8 +38,8 @@ defmodule Zexbox.Metrics.ClientTest do end) =~ "Failed to write metric to InfluxDB: %RuntimeError{message: \"Bork\"}" end - test_with_mock "skips writing and returns {:ok, metrics} when metrics disabled for process", Connection, - write: fn _metrics -> raise "should not be called" end do + test_with_mock "skips writing and returns {:ok, metrics} when metrics disabled for process", + Connection, write: fn _metrics -> raise "should not be called" end do Zexbox.Metrics.disable_for_process() assert {:ok, @map} = Client.write_metric(@map) Zexbox.Metrics.enable_for_process() @@ -48,10 +48,12 @@ defmodule Zexbox.Metrics.ClientTest do test_with_mock "skips writing from task when parent process disabled metrics", Connection, write: fn _metrics -> raise "should not be called" end do Zexbox.Metrics.disable_for_process() + task = Task.async(fn -> Client.write_metric(@map) end) + assert {:ok, @map} = Task.await(task) Zexbox.Metrics.enable_for_process() end diff --git a/test/zexbox/metrics/context_registry_test.exs b/test/zexbox/metrics/context_registry_test.exs index 0ebb002..55be3ec 100644 --- a/test/zexbox/metrics/context_registry_test.exs +++ b/test/zexbox/metrics/context_registry_test.exs @@ -67,4 +67,3 @@ defmodule Zexbox.Metrics.ContextRegistryTest do end end end - diff --git a/test/zexbox/metrics/context_test.exs b/test/zexbox/metrics/context_test.exs index a9f6e4a..94992af 100644 --- a/test/zexbox/metrics/context_test.exs +++ b/test/zexbox/metrics/context_test.exs @@ -42,4 +42,3 @@ defmodule Zexbox.Metrics.ContextTest do end end end - diff --git a/test/zexbox/metrics/metric_handler_test.exs b/test/zexbox/metrics/metric_handler_test.exs index c58f47e..a0b1da5 100644 --- a/test/zexbox/metrics/metric_handler_test.exs +++ b/test/zexbox/metrics/metric_handler_test.exs @@ -100,10 +100,11 @@ defmodule Zexbox.Metrics.MetricHandlerTest do end test "captures and logs any exceptions", %{event: event, metadata: metadata} do - log = capture_log(fn -> - MetricHandler.handle_event(event, nil, metadata, nil) - end) - + log = + capture_log(fn -> + MetricHandler.handle_event(event, nil, metadata, nil) + end) + assert log =~ "Exception creating controller series:" end From 8d6db9de1be43866c2e46dd0ca49d5c60c708d4c Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 12:10:50 +0000 Subject: [PATCH 10/15] Remove 1.17 support --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4ca890..5969888 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,9 +12,6 @@ jobs: fail-fast: false matrix: include: - - elixir: 1.17.x - otp: 27 - os: ubuntu-22.04 - elixir: 1.18.x otp: 27 os: ubuntu-22.04 From e331042e61590d61e340b9c74841022887c8dab4 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 12:56:54 +0000 Subject: [PATCH 11/15] Update context_test.exs --- test/zexbox/metrics/context_test.exs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/zexbox/metrics/context_test.exs b/test/zexbox/metrics/context_test.exs index 6234bb4..11309d3 100644 --- a/test/zexbox/metrics/context_test.exs +++ b/test/zexbox/metrics/context_test.exs @@ -3,12 +3,11 @@ defmodule Zexbox.Metrics.ContextTest do alias Zexbox.Metrics.{Context, ContextRegistry} - setup_all do - ensure_registry_started() - :ok - end - describe "disable_for_process/0 and enable_for_process/0" do + setup do + ensure_registry_started() + :ok + end test "toggles disabled? for the current process" do assert Context.disabled?() == false From 8d1c6d80afa4395609363f73aa7b22dae62baee1 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 13:05:34 +0000 Subject: [PATCH 12/15] Update context_test.exs --- test/zexbox/metrics/context_test.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/zexbox/metrics/context_test.exs b/test/zexbox/metrics/context_test.exs index 11309d3..6730880 100644 --- a/test/zexbox/metrics/context_test.exs +++ b/test/zexbox/metrics/context_test.exs @@ -8,6 +8,7 @@ defmodule Zexbox.Metrics.ContextTest do ensure_registry_started() :ok end + test "toggles disabled? for the current process" do assert Context.disabled?() == false From aa30a5aac9998e4526a5ccc11d5ea4bbda5ed460 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 14:01:49 +0000 Subject: [PATCH 13/15] Update series_test.exs --- test/zexbox/metrics/models/series_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/zexbox/metrics/models/series_test.exs b/test/zexbox/metrics/models/series_test.exs index fdbc8fb..26b0c50 100644 --- a/test/zexbox/metrics/models/series_test.exs +++ b/test/zexbox/metrics/models/series_test.exs @@ -35,7 +35,7 @@ defmodule Zexbox.Metrics.SeriesTest do metric = Series.new(measurement) assert metric.measurement == measurement - refute is_nil(metric.timestamp) + assert %DateTime{} = metric.timestamp end test "field/3" do From 975277fb2305e443c74210e44c2f77493604cb54 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 14:05:27 +0000 Subject: [PATCH 14/15] Flaky fix --- test/zexbox/metrics/client_test.exs | 17 +++++------------ test/zexbox/metrics/context_registry_test.exs | 18 ++++++------------ test/zexbox/metrics/context_test.exs | 9 +-------- test/zexbox/metrics/metric_handler_test.exs | 14 ++------------ 4 files changed, 14 insertions(+), 44 deletions(-) diff --git a/test/zexbox/metrics/client_test.exs b/test/zexbox/metrics/client_test.exs index fd585d0..44617e5 100644 --- a/test/zexbox/metrics/client_test.exs +++ b/test/zexbox/metrics/client_test.exs @@ -5,11 +5,6 @@ defmodule Zexbox.Metrics.ClientTest do alias Zexbox.Metrics.{Client, Connection, Series} alias Zexbox.Metrics.ContextRegistry - setup_all do - ensure_registry_started() - :ok - end - @map %{ measurement: "my_measurement", fields: %{ @@ -21,6 +16,11 @@ defmodule Zexbox.Metrics.ClientTest do } describe "write_metric/1" do + setup do + start_supervised!(ContextRegistry) + :ok + end + test_with_mock "writes the metric when given a series", Connection, write: fn metrics -> {:ok, metrics} end do series = struct(Series, @map) @@ -60,11 +60,4 @@ defmodule Zexbox.Metrics.ClientTest do Zexbox.Metrics.enable_for_process() end end - - defp ensure_registry_started do - case Process.whereis(ContextRegistry) do - nil -> {:ok, _pid} = ContextRegistry.start_link() - _pid -> :ok - end - end end diff --git a/test/zexbox/metrics/context_registry_test.exs b/test/zexbox/metrics/context_registry_test.exs index 26c6d00..f2f9a95 100644 --- a/test/zexbox/metrics/context_registry_test.exs +++ b/test/zexbox/metrics/context_registry_test.exs @@ -3,12 +3,13 @@ defmodule Zexbox.Metrics.ContextRegistryTest do alias Zexbox.Metrics.ContextRegistry - setup_all do - ensure_registry_started() - :ok - end - describe "register/1, unregister/1, disabled?/1" do + setup do + # Start a supervised ContextRegistry for each test + # This ensures a clean state and proper cleanup + start_supervised!(ContextRegistry) + :ok + end test "registers and unregisters a pid" do pid = self() @@ -59,11 +60,4 @@ defmodule Zexbox.Metrics.ContextRegistryTest do eventually(predicate, attempts - 1) end end - - defp ensure_registry_started do - case Process.whereis(ContextRegistry) do - nil -> {:ok, _pid} = ContextRegistry.start_link() - _pid -> :ok - end - end end diff --git a/test/zexbox/metrics/context_test.exs b/test/zexbox/metrics/context_test.exs index 6730880..b068a20 100644 --- a/test/zexbox/metrics/context_test.exs +++ b/test/zexbox/metrics/context_test.exs @@ -5,7 +5,7 @@ defmodule Zexbox.Metrics.ContextTest do describe "disable_for_process/0 and enable_for_process/0" do setup do - ensure_registry_started() + start_supervised!(ContextRegistry) :ok end @@ -34,11 +34,4 @@ defmodule Zexbox.Metrics.ContextTest do :ok = Zexbox.Metrics.enable_for_process() end end - - defp ensure_registry_started do - case Process.whereis(ContextRegistry) do - nil -> {:ok, _pid} = ContextRegistry.start_link() - _pid -> :ok - end - end end diff --git a/test/zexbox/metrics/metric_handler_test.exs b/test/zexbox/metrics/metric_handler_test.exs index 0b70dbf..dd845d8 100644 --- a/test/zexbox/metrics/metric_handler_test.exs +++ b/test/zexbox/metrics/metric_handler_test.exs @@ -5,11 +5,6 @@ defmodule Zexbox.Metrics.MetricHandlerTest do alias Zexbox.Metrics.{Connection, ControllerSeries, MetricHandler} alias Zexbox.Metrics.ContextRegistry - setup_all do - ensure_registry_started() - :ok - end - defmodule MockClient do @spec write_metric(ControllerSeries.t()) :: ControllerSeries.t() def write_metric(metric) do @@ -19,6 +14,8 @@ defmodule Zexbox.Metrics.MetricHandlerTest do describe "handle_event/4" do setup do + start_supervised!(ContextRegistry) + event = [:phoenix, :endpoint, :stop] measurements = %{duration: 1_000_000_000} @@ -122,11 +119,4 @@ defmodule Zexbox.Metrics.MetricHandlerTest do end end end - - defp ensure_registry_started do - case Process.whereis(ContextRegistry) do - nil -> {:ok, _pid} = ContextRegistry.start_link() - _pid -> :ok - end - end end From 0c99c096df05b9cb64841b6711e2b6ec12039572 Mon Sep 17 00:00:00 2001 From: Kent Hawkings Date: Tue, 3 Feb 2026 14:21:53 +0000 Subject: [PATCH 15/15] ffs --- test/zexbox/metrics/context_registry_test.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/zexbox/metrics/context_registry_test.exs b/test/zexbox/metrics/context_registry_test.exs index f2f9a95..3e70128 100644 --- a/test/zexbox/metrics/context_registry_test.exs +++ b/test/zexbox/metrics/context_registry_test.exs @@ -10,6 +10,7 @@ defmodule Zexbox.Metrics.ContextRegistryTest do start_supervised!(ContextRegistry) :ok end + test "registers and unregisters a pid" do pid = self()