Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
0598-Adjust-time-outs.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0598-Adjust-time-outs.patch of Package erlang
From 8e34ddad8fe19c6544111c0551b2de729ce5c2d8 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen <raimo@erlang.org> Date: Mon, 5 Dec 2022 16:54:37 +0100 Subject: [PATCH] Adjust time-outs Also set some time-outs in one code position instead of all over the function. --- lib/stdlib/test/gen_statem_SUITE.erl | 130 ++++++++++++++------------- 1 file changed, 66 insertions(+), 64 deletions(-) diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl index 9b4ee9413f..cb8bee9fab 100644 --- a/lib/stdlib/test/gen_statem_SUITE.erl +++ b/lib/stdlib/test/gen_statem_SUITE.erl @@ -1512,11 +1512,12 @@ replace_state(Config) -> %% Hibernation hibernate(Config) -> OldFl = process_flag(trap_exit, true), + WaitHibernate = 500, {ok,Pid0} = gen_statem:start_link( ?MODULE, start_arg(Config, hiber_now), []), - wait_erlang_hibernate(Pid0), + wait_erlang_hibernate(Pid0, WaitHibernate), stop_it(Pid0), receive {'EXIT',Pid0,normal} -> ok @@ -1529,38 +1530,38 @@ hibernate(Config) -> true = ({current_function,{erlang,hibernate,3}} =/= erlang:process_info(Pid,current_function)), hibernating = gen_statem:call(Pid, hibernate_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), good_morning = gen_statem:call(Pid, wakeup_sync), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), hibernating = gen_statem:call(Pid, hibernate_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), please_just_five_more = gen_statem:call(Pid, snooze_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), good_morning = gen_statem:call(Pid, wakeup_sync), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, hibernate_async), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, wakeup_async), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, hibernate_async), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, snooze_async), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, wakeup_async), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), - Pid ! hibernate_later, + Pid ! {hibernate_later, WaitHibernate div 2}, true = ({current_function,{erlang,hibernate,3}} =/= erlang:process_info(Pid, current_function)), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), 'alive!' = gen_statem:call(Pid, 'alive?'), true = ({current_function,{erlang,hibernate,3}} =/= erlang:process_info(Pid, current_function)), Pid ! hibernate_now, - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), 'alive!' = gen_statem:call(Pid, 'alive?'), true = @@ -1568,37 +1569,37 @@ hibernate(Config) -> erlang:process_info(Pid, current_function)), hibernating = gen_statem:call(Pid, hibernate_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), good_morning = gen_statem:call(Pid, wakeup_sync), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), hibernating = gen_statem:call(Pid, hibernate_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), please_just_five_more = gen_statem:call(Pid, snooze_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), good_morning = gen_statem:call(Pid, wakeup_sync), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, hibernate_async), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, wakeup_async), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, hibernate_async), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, snooze_async), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), ok = gen_statem:cast(Pid, wakeup_async), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), hibernating = gen_statem:call(Pid, hibernate_sync), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), sys:suspend(Pid), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), sys:resume(Pid), - wait_erlang_hibernate(Pid), - receive after 1000 -> ok end, - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, WaitHibernate), + receive after WaitHibernate -> ok end, + wait_erlang_hibernate(Pid, WaitHibernate), good_morning = gen_statem:call(Pid, wakeup_sync), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, WaitHibernate), stop_it(Pid), process_flag(trap_exit, OldFl), receive @@ -1611,73 +1612,74 @@ hibernate(Config) -> %% Auto-hibernation timeout auto_hibernate(Config) -> OldFl = process_flag(trap_exit, true), - HibernateAfterTimeout = 1000, + HibernateAfterTimeout = 500, + WaitTime = 1000, {ok,Pid} = gen_statem:start_link( ?MODULE, start_arg(Config, []), [{hibernate_after, HibernateAfterTimeout}]), %% After init test - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), %% After info test Pid ! {hping, self()}, receive {Pid, hpong} -> ok - after 1000 -> + after WaitTime -> ct:fail(info) end, - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), %% After cast test ok = gen_statem:cast(Pid, {hping, self()}), receive {Pid, hpong} -> ok - after 1000 -> + after WaitTime -> ct:fail(cast) end, - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), %% After call test hpong = gen_statem:call(Pid, hping), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), %% Timer test 1 TimerTimeout1 = HibernateAfterTimeout div 2, ok = gen_statem:call(Pid, {start_htimer, self(), TimerTimeout1}), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(TimerTimeout1), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), receive {Pid, htimer_timeout} -> ok - after 1000 -> + after WaitTime -> ct:fail(timer1) end, - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), %% Timer test 2 TimerTimeout2 = HibernateAfterTimeout * 2, ok = gen_statem:call(Pid, {start_htimer, self(), TimerTimeout2}), - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), receive {Pid, htimer_timeout} -> ok after TimerTimeout2 -> ct:fail(timer2) end, - is_not_in_erlang_hibernate(Pid), + is_not_in_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), timer:sleep(HibernateAfterTimeout), - wait_erlang_hibernate(Pid), + wait_erlang_hibernate(Pid, 2 * HibernateAfterTimeout), stop_it(Pid), process_flag(trap_exit, OldFl), receive @@ -1688,35 +1690,35 @@ auto_hibernate(Config) -> ok = verify_empty_msgq(). -wait_erlang_hibernate(Pid) -> +wait_erlang_hibernate(Pid, Time) -> receive after 1 -> ok end, - wait_erlang_hibernate_1(200, Pid). + wait_erlang_hibernate_1(Pid, Time, Time div 100). -wait_erlang_hibernate_1(0, Pid) -> +wait_erlang_hibernate_1(Pid, Time, _T) when Time =< 0 -> ct:log("~p\n", [erlang:process_info(Pid, current_function)]), ct:fail(should_be_in_erlang_hibernate_3); -wait_erlang_hibernate_1(N, Pid) -> +wait_erlang_hibernate_1(Pid, Time, T) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of {erlang,hibernate,3} -> ok; _ -> - receive after 10 -> ok end, - wait_erlang_hibernate_1(N-1, Pid) + receive after T -> ok end, + wait_erlang_hibernate_1(Pid, Time - T, T) end. -is_not_in_erlang_hibernate(Pid) -> +is_not_in_erlang_hibernate(Pid, Time) -> receive after 1 -> ok end, - is_not_in_erlang_hibernate_1(200, Pid). + is_not_in_erlang_hibernate_1(Pid, Time, Time div 100). -is_not_in_erlang_hibernate_1(0, _Pid) -> +is_not_in_erlang_hibernate_1(_Pid, Time, _T) when Time =< 0 -> ct:fail(should_not_be_in_erlang_hibernate_3); -is_not_in_erlang_hibernate_1(N, Pid) -> +is_not_in_erlang_hibernate_1(Pid, Time, T) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of {erlang,hibernate,3} -> - receive after 10 -> ok end, - is_not_in_erlang_hibernate_1(N-1, Pid); + receive after T -> ok end, + is_not_in_erlang_hibernate_1(Pid, Time - T, T); _ -> ok end. @@ -2972,8 +2974,8 @@ hiber_idle({call,From}, hibernate_sync, Data) -> {next_state,hiber_wakeup,Data, [{reply,From,hibernating}, hibernate]}; -hiber_idle(info, hibernate_later, _) -> - Tref = erlang:start_timer(1000, self(), hibernate), +hiber_idle(info, {hibernate_later, Time}, _) -> + Tref = erlang:start_timer(Time, self(), hibernate), {keep_state,Tref}; hiber_idle(info, hibernate_now, Data) -> {keep_state,Data, -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor