Skip to content

Commit

Permalink
Add tests for run_parallel_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
x4lldux committed Mar 29, 2020
1 parent f7860e6 commit 8b66ae0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
77 changes: 77 additions & 0 deletions test/parallel_statem.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
%%% -*- coding: utf-8 -*-
%%% -*- erlang-indent-level: 2 -*-
%%% -------------------------------------------------------------------
%%% From X4lldux
%%%
%%% When there was a crash in sequential phase of `run_parallel_commands`
%%% the returned result was `{exception,_,_,_}` tuple, but when a crash
%%% occurred in the parallel phase, then the `run_parallel_commands`
%%% also crashed.
%%%
%%% -------------------------------------------------------------------

-module(parallel_statem).

%% -compile(export_all).
-export([initial_state/0, next_state/3, precondition/2, postcondition/3]).
-export([foo/1, crash/0]).
-export([prop_parallel_crash/0, prop_sequential_crash/0]).

-include_lib("proper/include/proper.hrl").


initial_state() ->
[].

precondition(_, _) ->
true.

next_state(S, _V, {call,_,_,[_Arg]}) ->
S.

postcondition(_, _, _) ->
true.

foo(_) ->
ok.

crash() ->
erlang:error(boom).


parallel_crash_commands() ->
exactly(
{
[{set,{var,1},{call,?MODULE,foo,[1]}}], % seq
[
[{set,{var,2},{call,?MODULE,crash,[]}}], % proc 1
[] % proc 2
]
}).

sequential_crash_commands() ->
exactly(
{
[{set,{var,1},{call,?MODULE,crash,[]}}], % seq
[
[{set,{var,2},{call,?MODULE,foo,[1]}}], % proc 1
[] % proc 2
]
}).

prop_parallel_crash() ->
?FORALL(Cmds, parallel_crash_commands(),
begin
{_S,_P,Res} = run_parallel_commands(?MODULE, Cmds),
assert_exception(Res)
end).

prop_sequential_crash() ->
?FORALL(Cmds, sequential_crash_commands(),
begin
{_S,_P,Res} = run_parallel_commands(?MODULE, Cmds),
assert_exception(Res)
end).

assert_exception({exception, error, boom, _}) -> true;
assert_exception(_) -> false.
4 changes: 4 additions & 0 deletions test/proper_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@ native_type_props_test_() ->
-record(untyped, {a, b = 12}).
-type untyped() :: #untyped{}.

parallel_statem_test_() ->
[?_passes(parallel_statem:prop_parallel_crash()),
?_passes(parallel_statem:prop_sequential_crash())].

true_props_test_() ->
[?_passes(?FORALL(X,integer(),X < X + 1)),
?_passes(?FORALL(A,atom(),list_to_atom(atom_to_list(A)) =:= A)),
Expand Down

0 comments on commit 8b66ae0

Please sign in to comment.