Skip to content

Commit af6f078

Browse files
committed
Fix error on concurrent pending calls. Closes #18
1 parent 0659c3b commit af6f078

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/flame/pool.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ defmodule FLAME.Pool do
423423
runner_count = runner_count(state)
424424

425425
cond do
426-
runner_count == 0 || (min_runner.count == state.max_concurrency && runner_count < state.max) ->
426+
runner_count == 0 || !min_runner ||
427+
(min_runner.count == state.max_concurrency && runner_count < state.max) ->
427428
if map_size(state.pending_runners) > 0 || state.async_boot_timer do
428429
waiting_in(state, deadline, from)
429430
else

test/flame_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ defmodule FLAME.FLAMETest do
5858
assert new_pool == Supervisor.which_children(runner_sup)
5959
end
6060

61+
@tag runner: [min: 0, max: 1, max_concurrency: 2]
62+
test "concurrent calls on fully pending runners",
63+
%{runner_sup: runner_sup} = config do
64+
assert Supervisor.which_children(runner_sup) == []
65+
parent = self()
66+
67+
Task.start_link(fn ->
68+
FLAME.call(config.test, fn ->
69+
send(parent, :called)
70+
Process.sleep(:infinity)
71+
end)
72+
end)
73+
74+
Task.start_link(fn ->
75+
FLAME.call(config.test, fn ->
76+
send(parent, :called)
77+
Process.sleep(:infinity)
78+
end)
79+
end)
80+
81+
assert_receive :called
82+
assert_receive :called
83+
end
84+
6185
def on_grow_start(meta) do
6286
send(:failure_test, {:grow_start, meta})
6387

0 commit comments

Comments
 (0)