diff options
author | Björn Gustavsson <[email protected]> | 2017-11-16 13:11:35 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2017-11-16 13:11:35 +0100 |
commit | 68dd05500dcad280417a2479f32fb6f7894ae712 (patch) | |
tree | e4bda059dea8ee0d3c3d94b635dae8423518a63a /erts/emulator/test | |
parent | f1bee5747a39adde2e8bab666d19c99a0069f5a9 (diff) | |
parent | 3679444fb654e9cba1252c6df0be5170e5388639 (diff) | |
download | otp-68dd05500dcad280417a2479f32fb6f7894ae712.tar.gz otp-68dd05500dcad280417a2479f32fb6f7894ae712.tar.bz2 otp-68dd05500dcad280417a2479f32fb6f7894ae712.zip |
Merge pull request #1626 from bjorng/bjorn/erts/fix-receive-opt/ERL-511
Fix broken receive mark after an exception
OTP-14782
Diffstat (limited to 'erts/emulator/test')
-rw-r--r-- | erts/emulator/test/receive_SUITE.erl | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/erts/emulator/test/receive_SUITE.erl b/erts/emulator/test/receive_SUITE.erl index a12019ec83..1fe11428b4 100644 --- a/erts/emulator/test/receive_SUITE.erl +++ b/erts/emulator/test/receive_SUITE.erl @@ -25,14 +25,16 @@ -include_lib("common_test/include/ct.hrl"). -export([all/0, suite/0, - call_with_huge_message_queue/1,receive_in_between/1]). + call_with_huge_message_queue/1,receive_in_between/1, + receive_opt_exception/1,receive_opt_recursion/1]). suite() -> [{ct_hooks,[ts_install_cth]}, {timetrap, {minutes, 3}}]. -all() -> - [call_with_huge_message_queue, receive_in_between]. +all() -> + [call_with_huge_message_queue, receive_in_between, + receive_opt_exception, receive_opt_recursion]. call_with_huge_message_queue(Config) when is_list(Config) -> Pid = spawn_link(fun echo_loop/0), @@ -113,6 +115,60 @@ receive_one() -> dummy -> ok end. +receive_opt_exception(_Config) -> + Recurse = fun() -> + %% Overwrite with the same mark, + %% and never consume it. + ThrowFun = fun() -> throw(aborted) end, + aborted = (catch do_receive_opt_exception(ThrowFun)), + ok + end, + do_receive_opt_exception(Recurse), + + %% Eat the second message. + receive + Ref when is_reference(Ref) -> ok + end. + +do_receive_opt_exception(Disturber) -> + %% Create a receive mark. + Ref = make_ref(), + self() ! Ref, + Disturber(), + receive + Ref -> + ok + after 0 -> + error(the_expected_message_was_not_there) + end. + +receive_opt_recursion(_Config) -> + Recurse = fun() -> + %% Overwrite with the same mark, + %% and never consume it. + NoOp = fun() -> ok end, + BlackHole = spawn(NoOp), + expected = do_receive_opt_recursion(BlackHole, NoOp, true), + ok + end, + do_receive_opt_recursion(self(), Recurse, false), + ok. + +do_receive_opt_recursion(Recipient, Disturber, IsInner) -> + Ref = make_ref(), + Recipient ! Ref, + Disturber(), + receive + Ref -> ok + after 0 -> + case IsInner of + true -> + expected; + false -> + error(the_expected_message_was_not_there) + end + end. + %%% %%% Common helpers. %%% |