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. elixir 1 · linux alpine/x64 …

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