Skip to content

Commit 77114a3

Browse files
committed
Merge pull request #2044 from pguyot/w51/fix-race-condition-in-test_ets
Fix a race condition in `test_ets` These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 7189ab6 + 334da04 commit 77114a3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/erlang_tests/test_ets.erl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,26 @@ assert_stored_key(T, Key) ->
277277
isolated(Fun) ->
278278
Ref = make_ref(),
279279
Self = self(),
280-
spawn_opt(
280+
{Pid, MRef} = spawn_opt(
281281
fun() ->
282282
Ret = Fun(),
283283
Self ! {ok, Ref, Ret}
284284
end,
285-
[]
285+
[monitor]
286286
),
287287
receive
288-
{ok, Ref, Ret} -> Ret
289-
after 500 -> {error, timeout}
288+
{ok, Ref, Ret} ->
289+
normal =
290+
receive
291+
{'DOWN', MRef, process, Pid, Reason} -> Reason
292+
end,
293+
Ret;
294+
{'DOWN', MRef, process, Pid, Reason} ->
295+
{error, {process_died, Reason}}
296+
after 500 ->
297+
demonitor(MRef, [flush]),
298+
exit(Pid, kill),
299+
{error, timeout}
290300
end.
291301

292302
assert_badarg(Fun) ->

0 commit comments

Comments
 (0)