CodeSampleX

Пример

nimble_pool 1.1.0: Check a resource out of a NimblePool and survive the failure paths: what the checkout function must return, which failures the pool recovers from, and which one silently leaks a worker

Проверенный пример — hex nimble_pool 1.1.0: Check a resource out of a NimblePool and survive the failure paths: what the checkout function must return, which…

sha256:b9a321085b5992dc0c641045e8b697e67dbb23c7f9958ea2d4e0b145d1a2f486

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

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

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

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

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

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

Кейс

HOW
Цель
Check a resource out of a NimblePool and survive the failure paths: what the checkout function must return, which failures the pool recovers from, and which one silently leaks a worker
Пакеты
Символы
  • NimblePool.start_link
  • NimblePool.checkout!
  • NimblePool.update
  • NimblePool.child_spec
  • NimblePool.init_pool
  • NimblePool.init_worker
  • NimblePool.handle_checkout
  • NimblePool.handle_checkin
  • NimblePool.handle_update
  • NimblePool.handle_cancelled
  • NimblePool.terminate_worker
Окружение
elixir 1
Создан
2026-08-14T20:12:13Z

Контракт

  1. assert :pool_size defaults to 10 rather than System.schedulers_online(), by counting exactly ten init_worker callbacks at start_link and no eleventh
  2. assert lazy: true starts no workers at all and builds exactly one on the first checkout
  3. assert the checkout! function body runs in the CLIENT process, and that the from it receives is {pool_pid, ref} carrying the POOL's pid, unlike GenServer.handle_call/3 where from carries the caller's
  4. assert checkout! returns the first element of the two-tuple and only handle_checkin/4 ever sees the second
  5. assert the asynchronous check-in does not race a re-checkout: twenty-five sequential checkouts against a one-worker pool all succeed
  6. assert raising inside the checkout! function is the recoverable failure: handle_cancelled(:checked_out) then terminate_worker(:error, ...) then a replacement init_worker, with handle_checkin skipped
  7. assert returning a value that is not a two-tuple raises {:try_clause, value} and silently leaks the worker: no handle_cancelled, no terminate_worker, no replacement, and every later checkout on that pool exits :timeout
  8. assert the leaked worker is reclaimed only when the calling process itself dies, which is when the pool's monitor fires handle_cancelled(:checked_out) and terminate_worker(:DOWN, ...)
  9. assert {:skip, exception, pool_state} from handle_checkout/4 raises that exception in the client while leaving the worker checked in and serving the next call, terminating nothing
  10. assert {:remove, reason, pool_state} from handle_checkout/4 retries the same checkout against another worker, so a remove keyed on the command destroys and rebuilds more workers than the pool size and the caller only ever sees its own checkout timeout
  11. assert a caller that times out while still queued cancels as :queued and tears down nothing, while a caller killed holding a worker cancels as :checked_out with terminate_worker reason :DOWN
  12. assert NimblePool.update/2 is called from inside the checkout! function with from, routes to handle_update/3, and replaces the worker_state that handle_checkin/4 later receives while the client_state passes through unchanged

Файлы

  • csx.json
  • lib/csx_nimble_pool/churn_worker.ex
  • lib/csx_nimble_pool/instrumented_worker.ex
  • mix.exs
  • mix.lock
  • test/contract_test.exs
  • test/test_helper.exs

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

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

anonymous