123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- %% ==========================================================================================================
- %% Syn - A global process registry.
- %%
- %% Copyright (C) 2015, Roberto Ostinelli <roberto@ostinelli.net>.
- %% All rights reserved.
- %%
- %% The MIT License (MIT)
- %%
- %% Copyright (c) 2015 Roberto Ostinelli
- %%
- %% Permission is hereby granted, free of charge, to any person obtaining a copy
- %% of this software and associated documentation files (the "Software"), to deal
- %% in the Software without restriction, including without limitation the rights
- %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- %% copies of the Software, and to permit persons to whom the Software is
- %% furnished to do so, subject to the following conditions:
- %%
- %% The above copyright notice and this permission notice shall be included in
- %% all copies or substantial portions of the Software.
- %%
- %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- %% THE SOFTWARE.
- %% ==========================================================================================================
- -module(syn_register_processes_SUITE).
- %% callbacks
- -export([all/0]).
- -export([init_per_suite/1, end_per_suite/1]).
- -export([groups/0, init_per_group/2, end_per_group/2]).
- %% tests
- -export([
- single_node_when_mnesia_is_ram_find_by_key/1,
- single_node_when_mnesia_is_ram_find_by_pid/1
- ]).
- %% include
- -include_lib("common_test/include/ct.hrl").
- %% ===================================================================
- %% Callbacks
- %% ===================================================================
- %% -------------------------------------------------------------------
- %% Function: all() -> GroupsAndTestCases | {skip,Reason}
- %% GroupsAndTestCases = [{group,GroupName} | TestCase]
- %% GroupName = atom()
- %% TestCase = atom()
- %% Reason = term()
- %% -------------------------------------------------------------------
- all() ->
- [
- {group, single_node_process_registration}
- ].
- %% -------------------------------------------------------------------
- %% Function: groups() -> [Group]
- %% Group = {GroupName,Properties,GroupsAndTestCases}
- %% GroupName = atom()
- %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
- %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
- %% TestCase = atom()
- %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
- %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
- %% repeat_until_any_ok | repeat_until_any_fail
- %% N = integer() | forever
- %% -------------------------------------------------------------------
- groups() ->
- [
- {single_node_process_registration, [shuffle], [
- single_node_when_mnesia_is_ram_find_by_key,
- single_node_when_mnesia_is_ram_find_by_pid
- ]}
- ].
- %% -------------------------------------------------------------------
- %% Function: init_per_suite(Config0) ->
- %% Config1 | {skip,Reason} |
- %% {skip_and_save,Reason,Config1}
- %% Config0 = Config1 = [tuple()]
- %% Reason = term()
- %% -------------------------------------------------------------------
- init_per_suite(Config) ->
- %% config
- [
- {slave_node_short_name, syn_slave}
- | Config
- ].
- %% -------------------------------------------------------------------
- %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
- %% Config0 = Config1 = [tuple()]
- %% -------------------------------------------------------------------
- end_per_suite(_Config) -> ok.
- %% -------------------------------------------------------------------
- %% Function: init_per_group(GroupName, Config0) ->
- %% Config1 | {skip,Reason} |
- %% {skip_and_save,Reason,Config1}
- %% GroupName = atom()
- %% Config0 = Config1 = [tuple()]
- %% Reason = term()
- %% -------------------------------------------------------------------
- init_per_group(_GroupName, Config) -> Config.
- %% -------------------------------------------------------------------
- %% Function: end_per_group(GroupName, Config0) ->
- %% void() | {save_config,Config1}
- %% GroupName = atom()
- %% Config0 = Config1 = [tuple()]
- %% -------------------------------------------------------------------
- end_per_group(_GroupName, _Config) ->
- clean_after_test().
- %% ===================================================================
- %% Tests
- %% ===================================================================
- single_node_when_mnesia_is_ram_find_by_key(_Config) ->
- %% set schema location
- application:set_env(mnesia, schema_location, ram),
- %% start
- ok = syn:start(),
- %% start process
- Pid = start_process(),
- %% retrieve
- undefined = syn:find_by_key(<<"my proc">>),
- %% register
- syn:register(<<"my proc">>, Pid),
- %% retrieve
- Pid = syn:find_by_key(<<"my proc">>),
- %% kill process
- kill_process(Pid),
- timer:sleep(100),
- %% retrieve
- undefined = syn:find_by_key(<<"my proc">>).
- single_node_when_mnesia_is_ram_find_by_pid(_Config) ->
- %% set schema location
- application:set_env(mnesia, schema_location, ram),
- %% start
- ok = syn:start(),
- %% start process
- Pid = start_process(),
- %% register
- syn:register(<<"my proc">>, Pid),
- %% retrieve
- <<"my proc">> = syn:find_by_pid(Pid),
- %% kill process
- kill_process(Pid),
- timer:sleep(100),
- %% retrieve
- undefined = syn:find_by_pid(Pid).
- %% ===================================================================
- %% Internal
- %% ===================================================================
- clean_after_test() ->
- %% stop mnesia
- mnesia:stop(),
- %% delete schema
- mnesia:delete_schema([node()]),
- %% stop syn
- syn:stop().
- start_process() ->
- Pid = spawn(?MODULE, process_main, []),
- Pid.
- kill_process(Pid) ->
- exit(Pid, kill).
- process_main() ->
- receive
- shutdown -> ok
- end.
|