diff options
author | Raimo Niskanen <[email protected]> | 2016-10-20 22:28:10 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2016-10-26 10:13:25 +0200 |
commit | 0b4deedf278273205c9dcd2ed5d0b4b4d4d8fb9d (patch) | |
tree | 59927c90348fbe4d9ea294cb00112aff14193f8e /lib/stdlib/test | |
parent | f3f2b83e873592bcec47431a787c7cfffdd60685 (diff) | |
download | otp-0b4deedf278273205c9dcd2ed5d0b4b4d4d8fb9d.tar.gz otp-0b4deedf278273205c9dcd2ed5d0b4b4d4d8fb9d.tar.bz2 otp-0b4deedf278273205c9dcd2ed5d0b4b4d4d8fb9d.zip |
Rework timeout handling
Handling of timers and timeouts has been cleaned up
and generalized.
Semantic change regarding state timeout zero:
Previously if one state caused a state timeout zero and
managed to stay in the same state to insert additional
timeout zero(s) in the next state callback invocation, then
there would be only one timeout zero event. The mindset
was that the machine was faster then the timeout zero.
This has changed with the mindset that all state callback
invocations should be independent, so now the machine will
get one state timeout zero event per started state timeout
zero.
Note that just using zero timeouts is fairly esoteric...
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r-- | lib/stdlib/test/gen_statem_SUITE.erl | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl index 28f9ab81fe..119546be98 100644 --- a/lib/stdlib/test/gen_statem_SUITE.erl +++ b/lib/stdlib/test/gen_statem_SUITE.erl @@ -742,26 +742,40 @@ state_timeout(_Config) -> %% Verify that {state_timeout,0,_} %% comes after next_event and that %% {timeout,0,_} is cancelled by - %% {state_timeout,0,_} + %% pending {state_timeout,0,_} {keep_state, {ok,2,Data}, [{timeout,0,3}]}; - (state_timeout, 2, {ok,2,{Time,From}}) -> - {next_state, state3, 3, + (state_timeout, 2, {ok,2,Data}) -> + %% Verify that timeout 0's are processed + %% in order + {keep_state, {ok,3,Data}, + [{timeout,0,4},{state_timeout,0,5}]}; + (timeout, 4, {ok,3,Data}) -> + %% Verify that timeout 0 is cancelled by + %% enqueued state_timeout 0 and that + %% multiple state_timeout 0 can be enqueued + {keep_state, {ok,4,Data}, + [{state_timeout,0,6},{timeout,0,7}]}; + (state_timeout, 5, {ok,4,Data}) -> + {keep_state, {ok,5,Data}}; + (state_timeout, 6, {ok,5,{Time,From}}) -> + {next_state, state3, 6, [{reply,From,ok}, - {state_timeout,Time,3}]} + {state_timeout,Time,8}]} end, state3 => fun - (info, message_to_self, 3) -> - {keep_state, '3'}; - ({call,From}, check, '3') -> + (info, message_to_self, 6) -> + {keep_state, 7}; + ({call,From}, check, 7) -> {keep_state, From}; - (state_timeout, 3, From) -> + (state_timeout, 8, From) -> {stop_and_reply, normal, {reply,From,ok}} end}, {ok,STM} = gen_statem:start_link(?MODULE, {map_statem,Machine,[]}, []), + sys:trace(STM, true), TRef = erlang:start_timer(1000, self(), kull), ok = gen_statem:call(STM, {go,500}), ok = gen_statem:call(STM, check), |