Skip to content

Commit 3320a11

Browse files
committed
Ensure sync tests are executed
1 parent a992ee9 commit 3320a11

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

lib/ex_unit/lib/ex_unit/runner.ex

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ defmodule ExUnit.Runner do
125125

126126
# Run all sync modules directly
127127
for pair <- sync_modules do
128-
running = spawn_modules(config, [pair], false, %{})
128+
running = spawn_modules(config, [[pair]], false, %{})
129129
running != %{} and wait_until_available(config, running)
130130
end
131131

@@ -161,23 +161,18 @@ defmodule ExUnit.Runner do
161161
running
162162
end
163163

164-
defp spawn_modules(
165-
config,
166-
[{_group, group_modules} | modules],
167-
async?,
168-
running
169-
) do
164+
defp spawn_modules(config, [[_ | _] = modules | groups], async?, running) do
170165
if max_failures_reached?(config) do
171166
running
172167
else
173168
{pid, ref} =
174169
spawn_monitor(fn ->
175-
Enum.each(group_modules, fn {module, params} ->
170+
Enum.each(modules, fn {module, params} ->
176171
run_module(config, module, async?, params)
177172
end)
178173
end)
179174

180-
spawn_modules(config, modules, async?, Map.put(running, ref, pid))
175+
spawn_modules(config, groups, async?, Map.put(running, ref, pid))
181176
end
182177
end
183178

lib/ex_unit/lib/ex_unit/server.ex

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule ExUnit.Server do
2323
[{name, %{}}]
2424
end
2525

26-
case GenServer.call(@name, {:add, {async?, group}, modules}, @timeout) do
26+
case GenServer.call(@name, {:add, async?, group, modules}, @timeout) do
2727
:ok ->
2828
:ok
2929

@@ -82,7 +82,7 @@ defmodule ExUnit.Server do
8282
# Called by the runner when --repeat-until-failure is used.
8383
def handle_call({:restore_modules, async_modules, sync_modules}, _from, state) do
8484
{async_modules, async_groups} =
85-
Enum.reduce(async_modules, {[], []}, fn
85+
Enum.map_reduce(async_modules, %{}, fn
8686
{nil, [module]}, {modules, groups} ->
8787
{[{:module, module} | modules], groups}
8888

@@ -130,28 +130,28 @@ defmodule ExUnit.Server do
130130
{:reply, diff, take_modules(%{state | loaded: :done})}
131131
end
132132

133-
def handle_call({:add, {false = _async, _group}, names}, _from, %{loaded: loaded} = state)
133+
def handle_call({:add, false = _async, _group, names}, _from, %{loaded: loaded} = state)
134134
when is_integer(loaded) do
135135
state =
136136
update_in(state.sync_modules, &Enum.reduce(names, &1, fn name, q -> :queue.in(name, q) end))
137137

138138
{:reply, :ok, state}
139139
end
140140

141-
def handle_call({:add, {true = _async, nil = _group}, names}, _from, %{loaded: loaded} = state)
141+
def handle_call({:add, true = _async, nil = _group, names}, _from, %{loaded: loaded} = state)
142142
when is_integer(loaded) do
143143
state =
144144
update_in(
145145
state.async_modules,
146146
&Enum.reduce(names, &1, fn name, q -> :queue.in({:module, name}, q) end)
147147
)
148148

149-
{:reply, :ok, state}
149+
{:reply, :ok, take_modules(state)}
150150
end
151151

152-
def handle_call({:add, {true = _async, group}, names}, _from, %{loaded: loaded} = state)
152+
def handle_call({:add, true = _async, group, names}, _from, %{loaded: loaded} = state)
153153
when is_integer(loaded) do
154-
state =
154+
{async_groups, async_modules} =
155155
case state.async_groups do
156156
%{^group => entries} = async_groups ->
157157
{%{async_groups | group => names ++ entries}, state.async_modules}
@@ -160,11 +160,13 @@ defmodule ExUnit.Server do
160160
{Map.put(async_groups, group, names), :queue.in({:group, group}, state.async_modules)}
161161
end
162162

163-
{:reply, :ok, state}
163+
{:reply, :ok,
164+
take_modules(%{state | async_groups: async_groups, async_modules: async_modules})}
164165
end
165166

166-
def handle_call({:add, {_async?, _group}, _names}, _from, state),
167-
do: {:reply, :already_running, state}
167+
def handle_call({:add, _async?, _group, _names}, _from, state) do
168+
{:reply, :already_running, state}
169+
end
168170

169171
defp take_modules(%{waiting: nil} = state) do
170172
state
@@ -185,16 +187,16 @@ defmodule ExUnit.Server do
185187
{async_modules, remaining_modules} = take_until(count, state.async_modules)
186188

187189
{async_modules, remaining_groups} =
188-
Enum.reduce(async_modules, {[], state.async_groups}, fn
189-
{:module, module}, {collected_modules, async_groups} ->
190-
{[{nil, [module]} | collected_modules], async_groups}
190+
Enum.map_reduce(async_modules, state.async_groups, fn
191+
{:module, module}, async_groups ->
192+
{[module], async_groups}
191193

192-
{:group, group}, {collected_modules, async_groups} ->
194+
{:group, group}, async_groups ->
193195
{group_modules, async_groups} = Map.pop!(async_groups, group)
194-
{[{group, Enum.reverse(group_modules)} | collected_modules], async_groups}
196+
{Enum.reverse(group_modules), async_groups}
195197
end)
196198

197-
GenServer.reply(from, Enum.reverse(async_modules))
199+
GenServer.reply(from, async_modules)
198200

199201
%{
200202
state

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ defmodule ExUnitTest do
12181218
assert third =~ "ThirdTestFIFO"
12191219
end
12201220

1221-
test "async test groups are run in compile order (FIFO)" do
1221+
test "groups are run in compile order (FIFO)" do
12221222
defmodule RedOneFIFO do
12231223
use ExUnit.Case, async: true, group: :red
12241224

@@ -1266,7 +1266,7 @@ defmodule ExUnitTest do
12661266
assert fourth =~ "BlueTwoFIFO"
12671267
end
12681268

1269-
test "can filter async tests" do
1269+
test "filters async tests" do
12701270
defmodule FirstTestAsyncTrue do
12711271
use ExUnit.Case, async: true
12721272

@@ -1295,11 +1295,10 @@ defmodule ExUnitTest do
12951295
run_with_filter([include: [async: true], exclude: [:test]], [])
12961296

12971297
assert {%{failures: 0, skipped: 0, total: 3, excluded: 2}, _} =
1298-
run_with_filter([include: [async: false], exclude: [:test]], [
1299-
FirstTestAsyncTrue,
1300-
SecondTestAsyncTrue,
1301-
FirstTestAsyncFalse
1302-
])
1298+
run_with_filter(
1299+
[include: [async: false], exclude: [:test]],
1300+
[FirstTestAsyncTrue, SecondTestAsyncTrue, FirstTestAsyncFalse]
1301+
)
13031302
end
13041303

13051304
## Helpers
@@ -1316,8 +1315,7 @@ defmodule ExUnitTest do
13161315
|> Keyword.merge(filters)
13171316
|> Keyword.merge(colors: [enabled: false])
13181317

1319-
output = capture_io(fn -> Process.put(:capture_result, ExUnit.Runner.run(opts, nil)) end)
1320-
{Process.get(:capture_result) |> elem(0), output}
1318+
with_io(fn -> ExUnit.Runner.run(opts, nil) |> elem(0) end)
13211319
end
13221320

13231321
defp next_message_in_mailbox() do

0 commit comments

Comments
 (0)