Skip to content

Commit

Permalink
Merge branch 'release/v0.7.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
general-CbIC committed Jun 3, 2023
2 parents 07c9a9e + 2a6c119 commit 67c1074
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: false,
strict: true,
#
# To modify the timeout for parsing files, change this value:
#
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
otp: '25'
- elixir: '1.14'
otp: '25'
- elixir: '1.14'
otp: '26'
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -63,7 +65,7 @@ jobs:
- name: Run dialyzer
uses: erlef/setup-beam@v1
with:
otp-version: '25'
otp-version: '26'
elixir-version: '1.14'
- run: mix do deps.get, compile
- run: mix check
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 25.2.1
elixir 1.14.3-otp-25
erlang 26.0
elixir 1.14.4-otp-26
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.1] - 2023-06-03

### Fixed

- Fix the shutdown process: stop workers before the pool ([issue](https://github.com/general-CbIC/poolex/issues/44)).

## [0.7.0] - 2023-04-13

### Added

- Added `FIFO` worker's implementation. [About implemetations](https://hexdocs.pm/poolex/custom-implementations.html)
- Added `FIFO` worker's implementation ([About implemetations](https://hexdocs.pm/poolex/workers-and-callers-implementations.html)).

## [0.6.1] - 2023-03-25

Expand Down Expand Up @@ -161,7 +167,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Supported main interface `Poolex.run/3` with `:timeout` option.

[unreleased]: https://github.com/general-CbIC/poolex/compare/v0.7.0...HEAD
[unreleased]: https://github.com/general-CbIC/poolex/compare/v0.7.1...HEAD
[0.7.1]: https://github.com/general-CbIC/poolex/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/general-CbIC/poolex/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/general-CbIC/poolex/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/general-CbIC/poolex/compare/v0.5.1...v0.6.0
Expand Down
8 changes: 8 additions & 0 deletions lib/poolex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,12 @@ defmodule Poolex do
{:noreply, %{state | waiting_callers_state: new_waiting_callers_state}}
end
end

@impl GenServer
def terminate(reason, %State{} = state) do
DynamicSupervisor.stop(state.supervisor, reason)
Monitoring.stop(state.monitor_id)

:ok
end
end
2 changes: 1 addition & 1 deletion lib/poolex/busy_workers.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Poolex.BusyWorkers do
@moduledoc false
alias Poolex.Workers.Behaviour
alias Poolex.Settings
alias Poolex.Workers.Behaviour

@doc false
@spec init(Poolex.pool_id(), module()) :: Behaviour.state()
Expand Down
8 changes: 8 additions & 0 deletions lib/poolex/monitoring.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ defmodule Poolex.Monitoring do
{:ok, monitor_id}
end

@spec stop(monitor_id()) :: :ok
@doc false
def stop(monitor_id) do
:ets.delete(monitor_id)

:ok
end

@spec add(monitor_id(), pid(), kind_of_process()) :: :ok
@doc false
def add(monitor_id, process_pid, kind_of_process) do
Expand Down
2 changes: 1 addition & 1 deletion lib/poolex/waiting_callers.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Poolex.WaitingCallers do
@moduledoc false
alias Poolex.Settings
alias Poolex.Callers.Behaviour
alias Poolex.Settings

@doc false
@spec init(Poolex.pool_id(), module()) :: Behaviour.state()
Expand Down
2 changes: 1 addition & 1 deletion lib/poolex/workers/impl/erlang_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Poolex.Workers.Impl.ErlangQueue do
@behaviour Poolex.Workers.Behaviour

@impl true
def init() do
def init do
:queue.new()
end

Expand Down
2 changes: 1 addition & 1 deletion lib/poolex/workers/impl/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Poolex.Workers.Impl.List do
@behaviour Poolex.Workers.Behaviour

@impl true
def init() do
def init do
[]
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Poolex.MixProject do
package: package(),
source_url: "https://github.com/general-CbIC/poolex",
start_permanent: Mix.env() == :prod,
version: "0.7.0"
version: "0.7.1"
]
end

Expand Down
24 changes: 24 additions & 0 deletions test/poolex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,30 @@ defmodule PoolexTest do
end
end

describe "shutdown process" do
test "workers stop before the pool", %{pool_name: pool_name} do
{:ok, pool_pid} =
Poolex.start_link(pool_id: pool_name, worker_module: SomeWorker, workers_count: 1)

state = Poolex.get_state(pool_name)

supervisor_pid = state.supervisor
worker_pid = Poolex.run!(pool_name, fn pid -> pid end)

pool_monitor_ref = Process.monitor(pool_pid)
supervisor_monitor_ref = Process.monitor(supervisor_pid)
worker_monitor_ref = Process.monitor(worker_pid)

GenServer.stop(pool_name)

{:messages, [message_1, message_2, message_3]} = Process.info(self(), :messages)

assert message_1 == {:DOWN, worker_monitor_ref, :process, worker_pid, :shutdown}
assert message_2 == {:DOWN, supervisor_monitor_ref, :process, supervisor_pid, :normal}
assert message_3 == {:DOWN, pool_monitor_ref, :process, pool_pid, :normal}
end
end

defp pool_name do
1..10
|> Enum.map(fn _ -> Enum.random(?a..?z) end)
Expand Down
2 changes: 1 addition & 1 deletion test/support/some_busy_workers_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule SomeBusyWorkersImpl do
@behaviour Poolex.Workers.Behaviour

@impl true
def init() do
def init do
[]
end

Expand Down
2 changes: 1 addition & 1 deletion test/support/some_idle_workers_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule SomeIdleWorkersImpl do
@behaviour Poolex.Workers.Behaviour

@impl true
def init() do
def init do
[]
end

Expand Down

0 comments on commit 67c1074

Please sign in to comment.