aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test/gen_event_SUITE.erl
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
committerErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
commit84adefa331c4159d432d22840663c38f155cd4c1 (patch)
treebff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/stdlib/test/gen_event_SUITE.erl
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/stdlib/test/gen_event_SUITE.erl')
-rw-r--r--lib/stdlib/test/gen_event_SUITE.erl846
1 files changed, 846 insertions, 0 deletions
diff --git a/lib/stdlib/test/gen_event_SUITE.erl b/lib/stdlib/test/gen_event_SUITE.erl
new file mode 100644
index 0000000000..dc5ddebf53
--- /dev/null
+++ b/lib/stdlib/test/gen_event_SUITE.erl
@@ -0,0 +1,846 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(gen_event_SUITE).
+
+-include("test_server.hrl").
+
+-export([all/1]).
+-export([start/1, test_all/1, add_handler/1, add_sup_handler/1,
+ delete_handler/1, swap_handler/1, swap_sup_handler/1,
+ notify/1, sync_notify/1, call/1, info/1, hibernate/1]).
+
+all(suite) -> {req, [stdlib], [start, test_all, hibernate]}.
+
+%% --------------------------------------
+%% Start an event manager.
+%% --------------------------------------
+
+start(doc) -> [];
+start(suite) -> [];
+start(Config) when list(Config) ->
+ OldFl = process_flag(trap_exit, true),
+
+ ?line {ok, Pid0} = gen_event:start(), %anonymous
+ ?line [] = gen_event:which_handlers(Pid0),
+ ?line ok = gen_event:stop(Pid0),
+
+ ?line {ok, Pid1} = gen_event:start_link(), %anonymous
+ ?line [] = gen_event:which_handlers(Pid1),
+ ?line ok = gen_event:stop(Pid1),
+
+ ?line {ok, Pid2} = gen_event:start({local, my_dummy_name}),
+ ?line [] = gen_event:which_handlers(my_dummy_name),
+ ?line [] = gen_event:which_handlers(Pid2),
+ ?line ok = gen_event:stop(my_dummy_name),
+
+ ?line {ok, Pid3} = gen_event:start_link({local, my_dummy_name}),
+ ?line [] = gen_event:which_handlers(my_dummy_name),
+ ?line [] = gen_event:which_handlers(Pid3),
+ ?line ok = gen_event:stop(my_dummy_name),
+
+ ?line {ok, Pid4} = gen_event:start_link({global, my_dummy_name}),
+ ?line [] = gen_event:which_handlers({global, my_dummy_name}),
+ ?line [] = gen_event:which_handlers(Pid4),
+ ?line ok = gen_event:stop({global, my_dummy_name}),
+
+ ?line {ok, _} = gen_event:start_link({local, my_dummy_name}),
+ ?line {error, {already_started, _}} =
+ gen_event:start_link({local, my_dummy_name}),
+ ?line {error, {already_started, _}} =
+ gen_event:start({local, my_dummy_name}),
+ ?line ok = gen_event:stop(my_dummy_name),
+
+ ?line {ok, Pid5} = gen_event:start_link({global, my_dummy_name}),
+ ?line {error, {already_started, _}} =
+ gen_event:start_link({global, my_dummy_name}),
+ ?line {error, {already_started, _}} =
+ gen_event:start({global, my_dummy_name}),
+
+ exit(Pid5, shutdown),
+ receive
+ {'EXIT', Pid5, shutdown} -> ok
+ after 10000 ->
+ ?t:fail(exit_gen_event)
+ end,
+
+ ?t:messages_get(),
+ process_flag(trap_exit, OldFl),
+ ok.
+
+
+hibernate(suite) -> [];
+hibernate(Config) when is_list(Config) ->
+ ?line {ok,Pid} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line true = gen_event:call(my_dummy_handler, dummy_h, hibernate),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line Pid ! wake,
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line later = gen_event:call(my_dummy_handler, dummy_h, hibernate_later),
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line receive after 2000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line Pid ! wake,
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line gen_event:notify(my_dummy_handler,hibernate),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line gen_event:notify(my_dummy_handler,wakeup),
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line gen_event:notify(my_dummy_handler,hibernate),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line gen_event:sync_notify(my_dummy_handler,wakeup),
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line ok = gen_event:sync_notify(my_dummy_handler,hibernate),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line Pid ! wake,
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy1_h, [self()]),
+ ?line [_,_] = gen_event:which_handlers(my_dummy_handler),
+ ?line gen_event:notify(my_dummy_handler,hibernate),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line gen_event:notify(my_dummy_handler,wakeup),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line Pid ! wake,
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line Pid ! gnurf,
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line Pid ! sleep,
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid,current_function),
+ ?line Pid ! wake,
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid,current_function)),
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ?line {ok,Pid2} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self(),hibernate]),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid2,current_function),
+ ?line sys:suspend(my_dummy_handler),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid2,current_function),
+ ?line sys:resume(my_dummy_handler),
+ ?line receive after 1000 -> ok end,
+ ?line {current_function,{erlang,hibernate,3}} = erlang:process_info(Pid2,current_function),
+ ?line Pid2 ! wake,
+ ?line receive after 1000 -> ok end,
+ ?line true = ({current_function,{erlang,hibernate,3}} =/=
+ erlang:process_info(Pid2,current_function)),
+
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+
+ ok.
+
+
+test_all(suite) -> [add_handler, add_sup_handler, delete_handler,
+ swap_handler, swap_sup_handler, notify,
+ sync_notify, call, info].
+
+add_handler(doc) -> [];
+add_handler(suite) -> [];
+add_handler(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line {error, my_error} =
+ gen_event:add_handler(my_dummy_handler, dummy_h, make_error),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line {error, my_error} =
+ gen_event:add_handler(my_dummy_handler, {dummy_h, self()}, make_error),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,self()},
+ [self()]),
+ Self = self(),
+ ?line [{dummy_h, Self}, dummy_h] =
+ gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+add_sup_handler(doc) -> [];
+add_sup_handler(suite) -> [];
+add_sup_handler(Config) when list(Config) ->
+ ?line {ok,Pid} = gen_event:start({local, my_dummy_handler}),
+ ?line {error, my_error} =
+ gen_event:add_sup_handler(my_dummy_handler, dummy_h, make_error),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line exit(Pid, sup_died),
+ ?t:sleep(1000),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line {error, my_error} =
+ gen_event:add_handler(my_dummy_handler, {dummy_h, self()}, make_error),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, {dummy_h,self()},
+ [self()]),
+ Self = self(),
+ ?line [{dummy_h, Self}, dummy_h] =
+ gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:stop(my_dummy_handler),
+
+ ?line receive
+ {gen_event_EXIT, dummy_h, shutdown} ->
+ ok
+ after 1000 ->
+ ?t:fail({no,{gen_event_EXIT, dummy_h, shutdown}})
+ end,
+
+ ?line receive
+ {gen_event_EXIT, {dummy_h,Self}, shutdown} ->
+ ok
+ after 1000 ->
+ ?t:fail({no,{gen_event_EXIT, {dummy_h,Self},
+ shutdown}})
+ end,
+ ok.
+
+delete_handler(doc) -> [];
+delete_handler(suite) -> [];
+delete_handler(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line {error, module_not_found} =
+ gen_event:delete_handler(my_dummy_handler, duuuuuuuuumy, []),
+ ?line return_hej =
+ gen_event:delete_handler(my_dummy_handler, dummy_h, return_hej),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line ok =
+ gen_event:delete_handler(my_dummy_handler, dummy_h, []),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,2}, [self()]),
+ ?line {error, module_not_found} =
+ gen_event:delete_handler(my_dummy_handler, {duuuuuuuuumy,1}, []),
+ ?line return_hej =
+ gen_event:delete_handler(my_dummy_handler, {dummy_h,1}, return_hej),
+ ?line return_hej =
+ gen_event:delete_handler(my_dummy_handler, {dummy_h,2}, return_hej),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,2}, [self()]),
+ ?line ok =
+ gen_event:delete_handler(my_dummy_handler, {dummy_h,2}, []),
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+swap_handler(doc) -> [];
+swap_handler(suite) -> [];
+swap_handler(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line {error, non_existing} =
+ gen_event:swap_handler(my_dummy_handler, {faulty_h, swap},
+ {dummy1_h, []}),
+ ?line ok =
+ gen_event:swap_handler(my_dummy_handler, {dummy_h, swap},
+ {dummy1_h, swap}),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:delete_handler(my_dummy_handler, dummy1_h, []),
+
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]),
+ ?line {error, non_existing} =
+ gen_event:swap_handler(my_dummy_handler, {faulty_h, swap},
+ {dummy1_h, []}),
+ ?line ok =
+ gen_event:swap_handler(my_dummy_handler, {{dummy_h,3}, swap},
+ {{dummy1_h,4}, swap}),
+ ?line [{dummy1_h,4}] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:delete_handler(my_dummy_handler, {dummy1_h,4}, []),
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+swap_sup_handler(doc) -> [];
+swap_sup_handler(suite) -> [];
+swap_sup_handler(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line {error, non_existing} =
+ gen_event:swap_handler(my_dummy_handler, {faulty_h, swap},
+ {dummy1_h, []}),
+ ?line ok =
+ gen_event:swap_handler(my_dummy_handler, {dummy_h, swap},
+ {dummy1_h, swap}),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:delete_handler(my_dummy_handler, dummy1_h, []),
+ ?line receive
+ {gen_event_EXIT, dummy1_h, normal} ->
+ ok
+ after 1000 ->
+ ?t:fail({no,{gen_event_EXIT, dummy1_h, normal}})
+ end,
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, {dummy_h,3},
+ [self()]),
+ ?line {error, non_existing} =
+ gen_event:swap_sup_handler(my_dummy_handler, {faulty_h, swap},
+ {dummy1_h, []}),
+ ?line ok =
+ gen_event:swap_sup_handler(my_dummy_handler, {{dummy_h,3}, swap},
+ {{dummy1_h,4}, swap}),
+ ?line [{dummy1_h,4}] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:delete_handler(my_dummy_handler, {dummy1_h,4}, []),
+ ?line receive
+ {gen_event_EXIT, {dummy1_h,4}, normal} ->
+ ok
+ after 1000 ->
+ ?t:fail({no,{gen_event_EXIT, {dummy1_h,4}, normal}})
+ end,
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+notify(doc) -> [];
+notify(suite) -> [];
+notify(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ Event = {event, self()},
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}),
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy1_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:notify(my_dummy_handler, delete_event),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line ok = gen_event:notify(my_dummy_handler, error_event),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Handler with id, {Mod,Id}
+
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,5}, [self()]),
+ ?line [{dummy_h,5}] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:notify(my_dummy_handler,
+ {swap_event, {dummy1_h, 9}, swap}),
+ ?t:sleep(1000),
+ ?line [{dummy1_h,9}] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy1_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:notify(my_dummy_handler, delete_event),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,a}, [self()]),
+
+ ?line ok = gen_event:notify(my_dummy_handler, error_event),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Supervised handler.
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy_h, Event} ->
+ ok
+ end,
+
+ ?line ok = gen_event:notify(my_dummy_handler, do_crash),
+ ?line receive
+ {gen_event_EXIT, dummy_h, {'EXIT',_}} ->
+ ok
+ end,
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}),
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:notify(my_dummy_handler, do_crash),
+ ?line receive
+ {gen_event_EXIT, dummy1_h, {'EXIT',_}} ->
+ ok
+ end,
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}),
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:notify(my_dummy_handler, delete_event),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+
+ ?line receive
+ {gen_event_EXIT, dummy1_h, normal} ->
+ ok
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+sync_notify(doc) -> [];
+sync_notify(suite) -> [];
+sync_notify(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ Event = {event, self()},
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:sync_notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:sync_notify(my_dummy_handler,
+ {swap_event, dummy1_h, swap}),
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:sync_notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy1_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:sync_notify(my_dummy_handler, delete_event),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line ok = gen_event:sync_notify(my_dummy_handler, error_event),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Handler with id, {Mod,Id}
+
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,5}, [self()]),
+ ?line [{dummy_h,5}] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:sync_notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:sync_notify(my_dummy_handler,
+ {swap_event, {dummy1_h, 9}, swap}),
+ ?t:sleep(1000),
+ ?line [{dummy1_h,9}] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:sync_notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy1_h, Event} ->
+ ok
+ end,
+ ?line ok = gen_event:sync_notify(my_dummy_handler, delete_event),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,a}, [self()]),
+
+ ?line ok = gen_event:sync_notify(my_dummy_handler, error_event),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Supervised handler.
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:sync_notify(my_dummy_handler, Event),
+ ?line receive
+ {dummy_h, Event} ->
+ ok
+ end,
+
+ ?line ok = gen_event:sync_notify(my_dummy_handler, do_crash),
+ ?line receive
+ {gen_event_EXIT, dummy_h, {'EXIT',_}} ->
+ ok
+ end,
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line ok = gen_event:sync_notify(my_dummy_handler,
+ {swap_event,dummy1_h,swap}),
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:sync_notify(my_dummy_handler, do_crash),
+ ?line receive
+ {gen_event_EXIT, dummy1_h, {'EXIT',_}} ->
+ ok
+ end,
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line ok = gen_event:sync_notify(my_dummy_handler,
+ {swap_event,dummy1_h,swap}),
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:sync_notify(my_dummy_handler, delete_event),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+
+ ?line receive
+ {gen_event_EXIT, dummy1_h, normal} ->
+ ok
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+call(doc) -> [];
+call(suite) -> [];
+call(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h, 1}, [self()]),
+ ?line [{dummy_h, 1}, dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line {'EXIT',_} = (catch gen_event:call(non_exist, dummy_h, hejsan)),
+ ?line {error, bad_module} =
+ gen_event:call(my_dummy_handler, bad_h, hejsan),
+ ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan),
+ ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, {dummy_h, 1},
+ hejsan),
+ ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan,
+ 10000),
+ ?line {'EXIT', {timeout, _}} =
+ (catch gen_event:call(my_dummy_handler, dummy_h, hejsan, 0)),
+ flush(),
+ ?line ok = gen_event:delete_handler(my_dummy_handler, {dummy_h, 1}, []),
+ ?line {ok, swapped} = gen_event:call(my_dummy_handler, dummy_h,
+ {swap_call,dummy1_h,swap}),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line {error, bad_module} =
+ gen_event:call(my_dummy_handler, dummy_h, hejsan),
+ ?line ok = gen_event:call(my_dummy_handler, dummy1_h, delete_call),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line {error, {return, faulty}} =
+ gen_event:call(my_dummy_handler, dummy_h, error_call),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line {error, {'EXIT', _}} =
+ gen_event:call(my_dummy_handler, dummy_h, exit_call),
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Handler with id, {Mod,Id}
+
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]),
+ ?line [{dummy_h,1}] = gen_event:which_handlers(my_dummy_handler),
+ ?line {error, bad_module} =
+ gen_event:call(my_dummy_handler, bad_h, hejsan),
+ ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, {dummy_h,1},
+ hejsan),
+ ?line {ok, swapped} = gen_event:call(my_dummy_handler, {dummy_h,1},
+ {swap_call,{dummy1_h,2},swap}),
+ ?line [{dummy1_h,2}] = gen_event:which_handlers(my_dummy_handler),
+ ?line {error, bad_module} =
+ gen_event:call(my_dummy_handler, dummy_h, hejsan),
+ ?line ok = gen_event:call(my_dummy_handler, {dummy1_h,2}, delete_call),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]),
+
+ ?line {error, {return, faulty}} =
+ gen_event:call(my_dummy_handler, {dummy_h,3}, error_call),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,4}, [self()]),
+
+ ?line {error, {'EXIT', _}} =
+ gen_event:call(my_dummy_handler, {dummy_h,4}, exit_call),
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Supervised handler.
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line {error, bad_module} =
+ gen_event:call(my_dummy_handler, bad_h, hejsan),
+ ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan),
+ ?line {ok, swapped} = gen_event:call(my_dummy_handler, dummy_h,
+ {swap_call,dummy1_h,swap}),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line {error, bad_module} =
+ gen_event:call(my_dummy_handler, dummy_h, hejsan),
+ ?line ok = gen_event:call(my_dummy_handler, dummy1_h, delete_call),
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+
+ ?line receive
+ {gen_event_EXIT, dummy1_h, normal} ->
+ ok
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line {error, {return, faulty}} =
+ gen_event:call(my_dummy_handler, dummy_h, error_call),
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+
+ ?line receive
+ {gen_event_EXIT, dummy_h, {return,faulty}} ->
+ ok
+ after 1000 ->
+ ?t:fail({no, {gen_event_EXIT, dummy_h, {return,faulty}}})
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line {error, {'EXIT', _}} =
+ gen_event:call(my_dummy_handler, dummy_h, exit_call),
+
+ ?line receive
+ {gen_event_EXIT, dummy_h, {'EXIT',_}} ->
+ ok
+ after 1000 ->
+ ?t:fail({no, {gen_event_EXIT, dummy_h, {'EXIT','_'}}})
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.
+
+flush() ->
+ receive _ -> flush() after 0 -> ok end.
+
+info(doc) -> [];
+info(suite) -> [];
+info(Config) when list(Config) ->
+ ?line {ok,_} = gen_event:start({local, my_dummy_handler}),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+ Info = {info, self()},
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line my_dummy_handler ! Info,
+ ?line receive
+ {dummy_h, Info} ->
+ ok
+ end,
+ ?line my_dummy_handler ! {swap_info,dummy1_h,swap},
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line my_dummy_handler ! Info,
+ ?line receive
+ {dummy1_h, Info} ->
+ ok
+ end,
+ ?line my_dummy_handler ! delete_info,
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line my_dummy_handler ! error_info,
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Handler with id, {Mod,Id}
+
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]),
+ ?line [{dummy_h,1}] = gen_event:which_handlers(my_dummy_handler),
+ ?line my_dummy_handler ! Info,
+ ?line receive
+ {dummy_h, Info} ->
+ ok
+ end,
+ ?line my_dummy_handler ! {swap_info,{dummy1_h,2},swap},
+ ?t:sleep(1000),
+ ?line [{dummy1_h,2}] = gen_event:which_handlers(my_dummy_handler),
+ ?line my_dummy_handler ! Info,
+ ?line receive
+ {dummy1_h, Info} ->
+ ok
+ end,
+ ?line my_dummy_handler ! delete_info,
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+ ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]),
+
+ ?line my_dummy_handler ! error_info,
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ %% Supervised handler
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line my_dummy_handler ! Info,
+ ?line receive
+ {dummy_h, Info} ->
+ ok
+ end,
+ ?line my_dummy_handler ! {swap_info,dummy1_h,swap},
+ ?t:sleep(1000),
+ ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler),
+ ?line my_dummy_handler ! Info,
+ ?line receive
+ {dummy1_h, Info} ->
+ ok
+ end,
+ ?line my_dummy_handler ! delete_info,
+ ?line receive
+ {dummy1_h, removed} ->
+ ok
+ end,
+
+ ?line receive
+ {gen_event_EXIT, dummy1_h, normal} ->
+ ok
+ after 1000 ->
+ ?t:fail({no, {gen_event_EXIT, dummy1_h, normal}})
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+
+ ?line my_dummy_handler ! error_info,
+ ?line receive
+ {dummy_h, returned_error} ->
+ ok
+ end,
+
+ ?line receive
+ {gen_event_EXIT, dummy_h, {return,faulty}} ->
+ ok
+ after 1000 ->
+ ?t:fail({no, {gen_event_EXIT, dummy_h, {return,faulty}}})
+ end,
+
+ ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]),
+ ?line my_dummy_handler ! do_crash,
+
+ ?line receive
+ {gen_event_EXIT, dummy_h, {'EXIT',_}} ->
+ ok
+ after 1000 ->
+ ?t:fail({no, {gen_event_EXIT, dummy_h, {'EXIT','_'}}})
+ end,
+
+ ?line [] = gen_event:which_handlers(my_dummy_handler),
+
+ ?line ok = gen_event:stop(my_dummy_handler),
+ ok.