CodeSampleX

Пример

nimble_pool 1.1.0: Verify that start_link eagerly checks worker module existence and validates pool_size type

Проверенный пример — hex nimble_pool 1.1.0: Verify that start_link eagerly checks worker module existence and validates pool_size type. Контракт выполнен на…

sha256:f3bdf79601e6d0cb079ae5187e83d3ea06e4b2ed2c35f223db15ccb9dd6be4d8

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
2
Заявленная среда elixir linux x64 elixir elixir mix

Среды запусков проверки

Окружение Контракт Этапы Запуск
elixir 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-16
elixir 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-18

Кейс

HOW
Цель
Verify that start_link eagerly checks worker module existence and validates pool_size type
Пакеты
Символы
  • NimblePool.start_link
Окружение
elixir
Создан
2026-08-16T15:08:03Z

Контракт

  1. NimblePool.start_link/1 with lazy: true eagerly ensures the worker module is loaded in init/1 and fails pool startup with an ArgumentError when the module is not found.
  2. NimblePool.start_link/1 strictly validates that :pool_size is a positive integer, raising an ArgumentError when passed atom options like :infinity that passed comparison in earlier versions.
  3. NimblePool.start_link/1 raises an ArgumentError when the required :worker option is omitted.

Файлы

  • NOTES.md
  • csx.json
  • mix.exs
  • mix.lock
  • test/contract_test.exs
  • test/test_helper.exs

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

NOTES.md
# NimblePool Worker and Option Validation

## What search_known_solution answered
`search_known_solution` returned existing sample `sha256:5dad1cd6420c0a31a656d4e6fa5d703e0a95522ccd354cd1b912b127624eaab9` (which demonstrates the `terminate_pool/2` GenServer state map structure on `v1.1.0`) and sample `sha256:604e80e0559a8cef2559c7cc549e4743383c6e7bd9a35924598667d1152f2ad7` (which proves idle worker ping throttling); this sample investigates startup option and worker module load validation changes introduced in `v1.1.0`.

## How the wrong version fails
On `v1.0.0`, starting a lazy pool (`lazy: true`) with an unresolvable worker module or an atom like `pool_size: :infinity` silently succeeds with a green build, returning `{:ok, pid}` instead of failing pool startup with an `ArgumentError`.
csx.json
{"buildCommand":["mix","deps.compile","--no-deps-check"],"case":{"believed":"A model expects that starting a lazy pool with lazy: true defers worker module validation until checkout, allowing start_link to return {:ok, pid} even when given an unresolvable worker module or an atom :infinity for pool_size.","caseId":"case:sha256:5343fe19c31eb054d01a5fce6de44c20f27beadbabe563192c3471728f6effda","contract":["NimblePool.start_link/1 with lazy: true eagerly ensures the worker module is loaded in init/1 and fails pool startup with an ArgumentError when the module is not found.","NimblePool.start_link/1 strictly validates that :pool_size is a positive integer, raising an ArgumentError when passed atom options like :infinity that passed comparison in earlier versions.","NimblePool.start_link/1 raises an ArgumentError when the required :worker option is omitted."],"goal":"Verify that start_link eagerly checks worker module existence and validates pool_size type","kind":"HOW","packages":["pkg:hex/nimble_pool@1.1.0"],"schemaVersion":1,"symbols":["NimblePool.start_link"]},"contractCommand":["mix","test","--no-deps-check"],"environment":{"arch":"x64","ecosystem":"hex","executionContext":"elixir","language":"elixir","os":"linux","packageManager":"mix","runtime":"elixir","schemaVersion":1},"license":"MIT-0","packages":["pkg:hex/nimble_pool@1.1.0"],"schemaVersion":1,"symbols":["NimblePool.start_link"],"verifierAdapter":"hex@1"}
mix.exs
defmodule NimblePoolOptionValidation.MixProject do
  use Mix.Project

  def project do
    [
      app: :nimble_pool_option_validation,
      version: "0.1.0",
      elixir: "~> 1.14 or ~> 1.15 or ~> 1.16 or ~> 1.17 or ~> 1.18",
      deps: deps()
    ]
  end

  def application do
    [extra_applications: []]
  end

  defp deps do
    [{:nimble_pool, "1.1.0"}]
  end
end
mix.lock
%{
  "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
}
test/contract_test.exs
defmodule WorkerValidationContractTest do
  use ExUnit.Case, async: false

  defmodule ValidWorker do
    @behaviour NimblePool

    @impl true
    def init_pool(arg), do: {:ok, arg}

    @impl true
    def init_worker(pool_state), do: {:ok, :worker_state, pool_state}

    @impl true
    def handle_checkout(_command, _from, worker_state, pool_state) do
      {:ok, :client_state, worker_state, pool_state}
    end

    @impl true
    def handle_checkin(_client_state, _from, worker_state, pool_state) do
      {:ok, worker_state, pool_state}
    end

    @impl true
    def terminate_worker(_reason, _worker_state, pool_state) do
      {:ok, pool_state}
    end
  end

  test "lazy: true pool eagerly validates worker module existence during start_link" do
    Process.flag(:trap_exit, true)
    unloaded_module = :NonExistentWorkerModule

    result = NimblePool.start_link(worker: {unloaded_module, :arg}, lazy: true)

    assert match?({:error, {%ArgumentError{message: "failed to load worker module " <> _}, _}}, result)
  end

  test "pool_size must be a positive integer, rejecting atoms like :infinity" do
    assert_raise ArgumentError, ~r/pool_size must be a positive integer/, fn ->
      NimblePool.start_link(worker: {ValidWorker, []}, pool_size: :infinity, lazy: true)
    end
  end

  test "omitting the required :worker option raises ArgumentError" do
    assert_raise ArgumentError, ~r/missing required :worker option/, fn ->
      NimblePool.start_link([])
    end
  end
end
test/test_helper.exs
ExUnit.start()

Исходный сидер

csx-seed