From d5d81621957f917473abd5d45e66d412ded14e3f Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Mon, 31 Jul 2023 14:28:50 +0700 Subject: [PATCH 1/2] Fixed release of workers --- CHANGELOG.md | 4 ++++ lib/poolex.ex | 2 +- test/poolex_test.exs | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fcba3..8cda071 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed a serious bug when working with the `idle_workers` set. Previous version retired. + ## [0.7.4] - 2023-07-23 ### Fixed diff --git a/lib/poolex.ex b/lib/poolex.ex index 47a2067..e53255b 100644 --- a/lib/poolex.ex +++ b/lib/poolex.ex @@ -458,7 +458,7 @@ defmodule Poolex do | idle_workers_state: IdleWorkers.add( state.idle_workers_impl, - state.busy_workers_state, + state.idle_workers_state, worker ) } diff --git a/test/poolex_test.exs b/test/poolex_test.exs index ebf3a37..472d168 100644 --- a/test/poolex_test.exs +++ b/test/poolex_test.exs @@ -41,6 +41,24 @@ defmodule PoolexTest do assert debug_info.waiting_callers_impl == SomeWaitingCallersImpl end + test "valid after using the worker" do + initial_fun = fn -> 0 end + pool_name = start_pool(worker_module: Agent, worker_args: [initial_fun], workers_count: 5) + + {:ok, 0} = Poolex.run(pool_name, fn pid -> Agent.get(pid, & &1) end) + + debug_info = Poolex.get_debug_info(pool_name) + + assert debug_info.__struct__ == Poolex.DebugInfo + assert debug_info.busy_workers_count == 0 + assert Enum.empty?(debug_info.busy_workers_pids) + assert debug_info.idle_workers_count == 5 + assert Enum.count(debug_info.idle_workers_pids) == 5 + assert debug_info.worker_module == Agent + assert debug_info.worker_args == [initial_fun] + assert debug_info.waiting_callers == [] + end + test "valid after holding some workers" do initial_fun = fn -> 0 end pool_name = start_pool(worker_module: Agent, worker_args: [initial_fun], workers_count: 5) From 030aebddc5e7b99d8fd909a0461c35c8fbf55229 Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Mon, 31 Jul 2023 14:40:31 +0700 Subject: [PATCH 2/2] Mark retired versions in CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cda071..f7e04b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a serious bug when working with the `idle_workers` set. Previous version retired. -## [0.7.4] - 2023-07-23 +## [0.7.4] - 2023-07-23 (RETIRED) ### Fixed @@ -137,7 +137,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix links in hex documentation. - Added missing spec for `get_debug_info/1`. -## [0.3.0] - 2023-02-03 +## [0.3.0] - 2023-02-03 (RETIRED) ### Added