syn_registry_SUITE.erl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. %% ==========================================================================================================
  2. %% Syn - A global Process Registry and Process Group manager.
  3. %%
  4. %% The MIT License (MIT)
  5. %%
  6. %% Copyright (c) 2015 Roberto Ostinelli <roberto@ostinelli.net> and Neato Robotics, Inc.
  7. %%
  8. %% Permission is hereby granted, free of charge, to any person obtaining a copy
  9. %% of this software and associated documentation files (the "Software"), to deal
  10. %% in the Software without restriction, including without limitation the rights
  11. %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. %% copies of the Software, and to permit persons to whom the Software is
  13. %% furnished to do so, subject to the following conditions:
  14. %%
  15. %% The above copyright notice and this permission notice shall be included in
  16. %% all copies or substantial portions of the Software.
  17. %%
  18. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. %% THE SOFTWARE.
  25. %% ==========================================================================================================
  26. -module(syn_registry_SUITE).
  27. %% callbacks
  28. -export([all/0]).
  29. -export([init_per_suite/1, end_per_suite/1]).
  30. -export([groups/0, init_per_group/2, end_per_group/2]).
  31. -export([init_per_testcase/2, end_per_testcase/2]).
  32. %% tests
  33. -export([
  34. single_node_when_mnesia_is_ram_find_by_key/1,
  35. single_node_when_mnesia_is_ram_find_by_key_with_meta/1,
  36. single_node_when_mnesia_is_ram_find_by_pid/1,
  37. single_node_when_mnesia_is_ram_find_by_pid_with_meta/1,
  38. single_node_when_mnesia_is_ram_re_register_error/1,
  39. single_node_when_mnesia_is_ram_unregister/1,
  40. single_node_when_mnesia_is_ram_process_count/1,
  41. single_node_when_mnesia_is_ram_callback_on_process_exit/1,
  42. single_node_when_mnesia_is_disc_find_by_key/1
  43. ]).
  44. -export([
  45. two_nodes_when_mnesia_is_ram_find_by_key/1,
  46. two_nodes_when_mnesia_is_ram_find_by_key_with_meta/1,
  47. two_nodes_when_mnesia_is_ram_process_count/1,
  48. two_nodes_when_mnesia_is_ram_callback_on_process_exit/1,
  49. two_nodes_when_mnesia_is_disc_find_by_pid/1
  50. ]).
  51. %% internals
  52. -export([registry_process_exit_callback_dummy/4]).
  53. %% include
  54. -include_lib("common_test/include/ct.hrl").
  55. %% ===================================================================
  56. %% Callbacks
  57. %% ===================================================================
  58. %% -------------------------------------------------------------------
  59. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  60. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  61. %% GroupName = atom()
  62. %% TestCase = atom()
  63. %% Reason = term()
  64. %% -------------------------------------------------------------------
  65. all() ->
  66. [
  67. {group, single_node_process_registration},
  68. {group, two_nodes_process_registration}
  69. ].
  70. %% -------------------------------------------------------------------
  71. %% Function: groups() -> [Group]
  72. %% Group = {GroupName,Properties,GroupsAndTestCases}
  73. %% GroupName = atom()
  74. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  75. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  76. %% TestCase = atom()
  77. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  78. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  79. %% repeat_until_any_ok | repeat_until_any_fail
  80. %% N = integer() | forever
  81. %% -------------------------------------------------------------------
  82. groups() ->
  83. [
  84. {single_node_process_registration, [shuffle], [
  85. single_node_when_mnesia_is_ram_find_by_key,
  86. single_node_when_mnesia_is_ram_find_by_key_with_meta,
  87. single_node_when_mnesia_is_ram_find_by_pid,
  88. single_node_when_mnesia_is_ram_find_by_pid_with_meta,
  89. single_node_when_mnesia_is_ram_re_register_error,
  90. single_node_when_mnesia_is_ram_unregister,
  91. single_node_when_mnesia_is_ram_process_count,
  92. single_node_when_mnesia_is_ram_callback_on_process_exit,
  93. single_node_when_mnesia_is_disc_find_by_key
  94. ]},
  95. {two_nodes_process_registration, [shuffle], [
  96. two_nodes_when_mnesia_is_ram_find_by_key,
  97. two_nodes_when_mnesia_is_ram_find_by_key_with_meta,
  98. two_nodes_when_mnesia_is_ram_process_count,
  99. two_nodes_when_mnesia_is_ram_callback_on_process_exit,
  100. two_nodes_when_mnesia_is_disc_find_by_pid
  101. ]}
  102. ].
  103. %% -------------------------------------------------------------------
  104. %% Function: init_per_suite(Config0) ->
  105. %% Config1 | {skip,Reason} |
  106. %% {skip_and_save,Reason,Config1}
  107. %% Config0 = Config1 = [tuple()]
  108. %% Reason = term()
  109. %% -------------------------------------------------------------------
  110. init_per_suite(Config) ->
  111. %% config
  112. [
  113. {slave_node_short_name, syn_slave}
  114. | Config
  115. ].
  116. %% -------------------------------------------------------------------
  117. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  118. %% Config0 = Config1 = [tuple()]
  119. %% -------------------------------------------------------------------
  120. end_per_suite(_Config) -> ok.
  121. %% -------------------------------------------------------------------
  122. %% Function: init_per_group(GroupName, Config0) ->
  123. %% Config1 | {skip,Reason} |
  124. %% {skip_and_save,Reason,Config1}
  125. %% GroupName = atom()
  126. %% Config0 = Config1 = [tuple()]
  127. %% Reason = term()
  128. %% -------------------------------------------------------------------
  129. init_per_group(two_nodes_process_registration, Config) ->
  130. %% start slave
  131. SlaveNodeShortName = proplists:get_value(slave_node_short_name, Config),
  132. {ok, SlaveNode} = syn_test_suite_helper:start_slave(SlaveNodeShortName),
  133. %% config
  134. [
  135. {slave_node, SlaveNode}
  136. | Config
  137. ];
  138. init_per_group(_GroupName, Config) -> Config.
  139. %% -------------------------------------------------------------------
  140. %% Function: end_per_group(GroupName, Config0) ->
  141. %% void() | {save_config,Config1}
  142. %% GroupName = atom()
  143. %% Config0 = Config1 = [tuple()]
  144. %% -------------------------------------------------------------------
  145. end_per_group(two_nodes_process_registration, Config) ->
  146. %% get slave node name
  147. SlaveNodeShortName = proplists:get_value(slave_node_short_name, Config),
  148. %% stop slave
  149. syn_test_suite_helper:stop_slave(SlaveNodeShortName);
  150. end_per_group(_GroupName, _Config) ->
  151. ok.
  152. % ----------------------------------------------------------------------------------------------------------
  153. % Function: init_per_testcase(TestCase, Config0) ->
  154. % Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
  155. % TestCase = atom()
  156. % Config0 = Config1 = [tuple()]
  157. % Reason = term()
  158. % ----------------------------------------------------------------------------------------------------------
  159. init_per_testcase(_TestCase, Config) ->
  160. Config.
  161. % ----------------------------------------------------------------------------------------------------------
  162. % Function: end_per_testcase(TestCase, Config0) ->
  163. % void() | {save_config,Config1} | {fail,Reason}
  164. % TestCase = atom()
  165. % Config0 = Config1 = [tuple()]
  166. % Reason = term()
  167. % ----------------------------------------------------------------------------------------------------------
  168. end_per_testcase(_TestCase, Config) ->
  169. %% get slave
  170. SlaveNode = proplists:get_value(slave_node, Config),
  171. syn_test_suite_helper:clean_after_test(SlaveNode).
  172. %% ===================================================================
  173. %% Tests
  174. %% ===================================================================
  175. single_node_when_mnesia_is_ram_find_by_key(_Config) ->
  176. %% set schema location
  177. application:set_env(mnesia, schema_location, ram),
  178. %% start
  179. ok = syn:start(),
  180. ok = syn:init(),
  181. %% start process
  182. Pid = syn_test_suite_helper:start_process(),
  183. %% retrieve
  184. undefined = syn:find_by_key(<<"my proc">>),
  185. %% register
  186. ok = syn:register(<<"my proc">>, Pid),
  187. %% retrieve
  188. Pid = syn:find_by_key(<<"my proc">>),
  189. %% kill process
  190. syn_test_suite_helper:kill_process(Pid),
  191. timer:sleep(100),
  192. %% retrieve
  193. undefined = syn:find_by_key(<<"my proc">>).
  194. single_node_when_mnesia_is_ram_find_by_key_with_meta(_Config) ->
  195. %% set schema location
  196. application:set_env(mnesia, schema_location, ram),
  197. %% start
  198. ok = syn:start(),
  199. ok = syn:init(),
  200. %% start process
  201. Pid1 = syn_test_suite_helper:start_process(),
  202. Pid2 = syn_test_suite_helper:start_process(),
  203. %% retrieve
  204. undefined = syn:find_by_key(<<"my proc 1">>, with_meta),
  205. undefined = syn:find_by_key(<<"my proc 2">>, with_meta),
  206. %% register
  207. Meta = [{some, 1}, {meta, <<"data">>}],
  208. ok = syn:register(<<"my proc 1">>, Pid1, Meta),
  209. ok = syn:register(<<"my proc 2">>, Pid2),
  210. %% retrieve
  211. {Pid1, Meta} = syn:find_by_key(<<"my proc 1">>, with_meta),
  212. {Pid2, undefined} = syn:find_by_key(<<"my proc 2">>, with_meta),
  213. %% kill process
  214. syn_test_suite_helper:kill_process(Pid1),
  215. syn_test_suite_helper:kill_process(Pid2),
  216. timer:sleep(100),
  217. %% retrieve
  218. undefined = syn:find_by_key(<<"my proc 1">>, with_meta),
  219. undefined = syn:find_by_key(<<"my proc 2">>, with_meta).
  220. single_node_when_mnesia_is_ram_find_by_pid(_Config) ->
  221. %% set schema location
  222. application:set_env(mnesia, schema_location, ram),
  223. %% start
  224. ok = syn:start(),
  225. ok = syn:init(),
  226. %% start process
  227. Pid = syn_test_suite_helper:start_process(),
  228. %% register
  229. ok = syn:register(<<"my proc">>, Pid),
  230. %% retrieve
  231. <<"my proc">> = syn:find_by_pid(Pid),
  232. %% kill process
  233. syn_test_suite_helper:kill_process(Pid),
  234. timer:sleep(100),
  235. %% retrieve
  236. undefined = syn:find_by_pid(Pid).
  237. single_node_when_mnesia_is_ram_find_by_pid_with_meta(_Config) ->
  238. %% set schema location
  239. application:set_env(mnesia, schema_location, ram),
  240. %% start
  241. ok = syn:start(),
  242. ok = syn:init(),
  243. %% start process
  244. Pid1 = syn_test_suite_helper:start_process(),
  245. Pid2 = syn_test_suite_helper:start_process(),
  246. %% retrieve
  247. undefined = syn:find_by_pid(Pid1, with_meta),
  248. undefined = syn:find_by_pid(Pid2, with_meta),
  249. %% register
  250. Meta = [{some, 1}, {meta, <<"data">>}],
  251. ok = syn:register(<<"my proc 1">>, Pid1, Meta),
  252. ok = syn:register(<<"my proc 2">>, Pid2),
  253. %% retrieve
  254. {<<"my proc 1">>, Meta} = syn:find_by_pid(Pid1, with_meta),
  255. {<<"my proc 2">>, undefined} = syn:find_by_pid(Pid2, with_meta),
  256. %% kill process
  257. syn_test_suite_helper:kill_process(Pid1),
  258. syn_test_suite_helper:kill_process(Pid2),
  259. timer:sleep(100),
  260. %% retrieve
  261. undefined = syn:find_by_pid(Pid1, with_meta),
  262. undefined = syn:find_by_pid(Pid2, with_meta).
  263. single_node_when_mnesia_is_ram_re_register_error(_Config) ->
  264. %% set schema location
  265. application:set_env(mnesia, schema_location, ram),
  266. %% start
  267. ok = syn:start(),
  268. ok = syn:init(),
  269. %% start process
  270. Pid = syn_test_suite_helper:start_process(),
  271. Pid2 = syn_test_suite_helper:start_process(),
  272. %% register
  273. ok = syn:register(<<"my proc">>, Pid),
  274. %% re-register same process
  275. ok = syn:register(<<"my proc">>, Pid, {with, meta}),
  276. %% register same process with another name
  277. {error, pid_already_registered} = syn:register(<<"my proc 2">>, Pid),
  278. %% register another process
  279. {error, taken} = syn:register(<<"my proc">>, Pid2),
  280. %% retrieve
  281. {Pid, {with, meta}} = syn:find_by_key(<<"my proc">>, with_meta),
  282. %% kill process
  283. syn_test_suite_helper:kill_process(Pid),
  284. timer:sleep(100),
  285. %% retrieve
  286. undefined = syn:find_by_key(<<"my proc">>),
  287. %% reuse
  288. ok = syn:register(<<"my proc">>, Pid2),
  289. %% retrieve
  290. Pid2 = syn:find_by_key(<<"my proc">>),
  291. %% kill process
  292. syn_test_suite_helper:kill_process(Pid),
  293. timer:sleep(100),
  294. %% retrieve
  295. undefined = syn:find_by_pid(Pid).
  296. single_node_when_mnesia_is_ram_unregister(_Config) ->
  297. %% set schema location
  298. application:set_env(mnesia, schema_location, ram),
  299. %% start
  300. ok = syn:start(),
  301. ok = syn:init(),
  302. %% start process
  303. Pid = syn_test_suite_helper:start_process(),
  304. %% unregister
  305. {error, undefined} = syn:unregister(<<"my proc">>),
  306. %% register
  307. ok = syn:register(<<"my proc">>, Pid),
  308. %% retrieve
  309. Pid = syn:find_by_key(<<"my proc">>),
  310. %% unregister
  311. ok = syn:unregister(<<"my proc">>),
  312. %% retrieve
  313. undefined = syn:find_by_key(<<"my proc">>),
  314. undefined = syn:find_by_pid(Pid),
  315. %% kill process
  316. syn_test_suite_helper:kill_process(Pid).
  317. single_node_when_mnesia_is_ram_process_count(_Config) ->
  318. %% set schema location
  319. application:set_env(mnesia, schema_location, ram),
  320. %% start
  321. ok = syn:start(),
  322. ok = syn:init(),
  323. %% count
  324. 0 = syn:registry_count(),
  325. %% start process
  326. Pid1 = syn_test_suite_helper:start_process(),
  327. Pid2 = syn_test_suite_helper:start_process(),
  328. Pid3 = syn_test_suite_helper:start_process(),
  329. %% register
  330. ok = syn:register(1, Pid1),
  331. ok = syn:register(2, Pid2),
  332. ok = syn:register(3, Pid3),
  333. %% count
  334. 3 = syn:registry_count(),
  335. %% kill processes
  336. syn_test_suite_helper:kill_process(Pid1),
  337. syn_test_suite_helper:kill_process(Pid2),
  338. syn_test_suite_helper:kill_process(Pid3),
  339. timer:sleep(100),
  340. %% count
  341. 0 = syn:registry_count().
  342. single_node_when_mnesia_is_ram_callback_on_process_exit(_Config) ->
  343. CurrentNode = node(),
  344. %% set schema location
  345. application:set_env(mnesia, schema_location, ram),
  346. %% load configuration variables from syn-test.config => this defines the callback
  347. syn_test_suite_helper:set_environment_variables(),
  348. %% start
  349. ok = syn:start(),
  350. ok = syn:init(),
  351. %% register global process
  352. ResultPid = self(),
  353. global:register_name(syn_register_process_SUITE_result, ResultPid),
  354. %% start process
  355. Pid = syn_test_suite_helper:start_process(),
  356. %% register
  357. Meta = {some, meta},
  358. ok = syn:register(<<"my proc">>, Pid, Meta),
  359. %% kill process
  360. syn_test_suite_helper:kill_process(Pid),
  361. %% check callback were triggered
  362. receive
  363. {exited, CurrentNode, <<"my proc">>, Pid, Meta, killed} -> ok
  364. after 2000 ->
  365. ok = registry_process_exit_callback_was_not_called_from_local_node
  366. end,
  367. %% unregister
  368. global:unregister_name(syn_register_process_SUITE_result).
  369. single_node_when_mnesia_is_disc_find_by_key(_Config) ->
  370. %% set schema location
  371. application:set_env(mnesia, schema_location, disc),
  372. %% create schema
  373. mnesia:create_schema([node()]),
  374. %% start
  375. ok = syn:start(),
  376. ok = syn:init(),
  377. %% start process
  378. Pid = syn_test_suite_helper:start_process(),
  379. %% retrieve
  380. undefined = syn:find_by_key(<<"my proc">>),
  381. %% register
  382. ok = syn:register(<<"my proc">>, Pid),
  383. %% retrieve
  384. Pid = syn:find_by_key(<<"my proc">>),
  385. %% kill process
  386. syn_test_suite_helper:kill_process(Pid),
  387. timer:sleep(100),
  388. %% retrieve
  389. undefined = syn:find_by_key(<<"my proc">>).
  390. two_nodes_when_mnesia_is_ram_find_by_key(Config) ->
  391. %% get slave
  392. SlaveNode = proplists:get_value(slave_node, Config),
  393. %% set schema location
  394. application:set_env(mnesia, schema_location, ram),
  395. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  396. %% start
  397. ok = syn:start(),
  398. ok = syn:init(),
  399. ok = rpc:call(SlaveNode, syn, start, []),
  400. ok = rpc:call(SlaveNode, syn, init, []),
  401. timer:sleep(100),
  402. %% start process
  403. Pid = syn_test_suite_helper:start_process(),
  404. %% retrieve
  405. undefined = syn:find_by_key(<<"my proc">>),
  406. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]),
  407. %% register
  408. ok = syn:register(<<"my proc">>, Pid),
  409. %% retrieve
  410. Pid = syn:find_by_key(<<"my proc">>),
  411. Pid = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]),
  412. %% kill process
  413. syn_test_suite_helper:kill_process(Pid),
  414. timer:sleep(100),
  415. %% retrieve
  416. undefined = syn:find_by_key(<<"my proc">>),
  417. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]).
  418. two_nodes_when_mnesia_is_ram_find_by_key_with_meta(Config) ->
  419. %% get slave
  420. SlaveNode = proplists:get_value(slave_node, Config),
  421. %% set schema location
  422. application:set_env(mnesia, schema_location, ram),
  423. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  424. %% start
  425. ok = syn:start(),
  426. ok = syn:init(),
  427. ok = rpc:call(SlaveNode, syn, start, []),
  428. ok = rpc:call(SlaveNode, syn, init, []),
  429. timer:sleep(100),
  430. %% start process
  431. Pid1 = syn_test_suite_helper:start_process(),
  432. Pid2 = syn_test_suite_helper:start_process(),
  433. %% retrieve
  434. undefined = syn:find_by_key(<<"my proc 1">>),
  435. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>]),
  436. undefined = syn:find_by_key(<<"my proc 2">>),
  437. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>]),
  438. %% register
  439. Meta = [{some, 1}, {meta, <<"data">>}],
  440. ok = syn:register(<<"my proc 1">>, Pid1, Meta),
  441. ok = syn:register(<<"my proc 2">>, Pid2),
  442. %% retrieve
  443. {Pid1, Meta} = syn:find_by_key(<<"my proc 1">>, with_meta),
  444. {Pid1, Meta} = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>, with_meta]),
  445. {Pid2, undefined} = syn:find_by_key(<<"my proc 2">>, with_meta),
  446. {Pid2, undefined} = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>, with_meta]),
  447. %% kill process
  448. syn_test_suite_helper:kill_process(Pid1),
  449. syn_test_suite_helper:kill_process(Pid2),
  450. timer:sleep(100),
  451. %% retrieve
  452. undefined = syn:find_by_key(<<"my proc 1">>),
  453. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>]),
  454. undefined = syn:find_by_key(<<"my proc 2">>),
  455. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>]).
  456. two_nodes_when_mnesia_is_ram_process_count(Config) ->
  457. %% get slave
  458. SlaveNode = proplists:get_value(slave_node, Config),
  459. CurrentNode = node(),
  460. %% set schema location
  461. application:set_env(mnesia, schema_location, ram),
  462. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  463. %% start
  464. ok = syn:start(),
  465. ok = syn:init(),
  466. ok = rpc:call(SlaveNode, syn, start, []),
  467. ok = rpc:call(SlaveNode, syn, init, []),
  468. timer:sleep(100),
  469. %% count
  470. 0 = syn:registry_count(),
  471. 0 = rpc:call(SlaveNode, syn, registry_count, []),
  472. 0 = syn:registry_count(CurrentNode),
  473. 0 = syn:registry_count(SlaveNode),
  474. 0 = rpc:call(SlaveNode, syn, registry_count, [CurrentNode]),
  475. 0 = rpc:call(SlaveNode, syn, registry_count, [SlaveNode]),
  476. %% start processes
  477. PidLocal1 = syn_test_suite_helper:start_process(),
  478. PidLocal2 = syn_test_suite_helper:start_process(),
  479. PidSlave = syn_test_suite_helper:start_process(SlaveNode),
  480. %% register
  481. ok = syn:register(1, PidLocal1),
  482. ok = syn:register(2, PidLocal2),
  483. ok = syn:register(3, PidSlave),
  484. timer:sleep(100),
  485. %% count
  486. 3 = syn:registry_count(),
  487. 3 = rpc:call(SlaveNode, syn, registry_count, []),
  488. 2 = syn:registry_count(CurrentNode),
  489. 1 = syn:registry_count(SlaveNode),
  490. 2 = rpc:call(SlaveNode, syn, registry_count, [CurrentNode]),
  491. 1 = rpc:call(SlaveNode, syn, registry_count, [SlaveNode]),
  492. %% kill processes
  493. syn_test_suite_helper:kill_process(PidLocal1),
  494. syn_test_suite_helper:kill_process(PidLocal2),
  495. syn_test_suite_helper:kill_process(PidSlave),
  496. timer:sleep(100),
  497. %% count
  498. 0 = syn:registry_count(),
  499. 0 = rpc:call(SlaveNode, syn, registry_count, []),
  500. 0 = syn:registry_count(CurrentNode),
  501. 0 = syn:registry_count(SlaveNode),
  502. 0 = rpc:call(SlaveNode, syn, registry_count, [CurrentNode]),
  503. 0 = rpc:call(SlaveNode, syn, registry_count, [SlaveNode]).
  504. two_nodes_when_mnesia_is_ram_callback_on_process_exit(Config) ->
  505. %% get slave
  506. SlaveNode = proplists:get_value(slave_node, Config),
  507. CurrentNode = node(),
  508. %% set schema location
  509. application:set_env(mnesia, schema_location, ram),
  510. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  511. %% load configuration variables from syn-test.config => this defines the callback
  512. syn_test_suite_helper:set_environment_variables(),
  513. syn_test_suite_helper:set_environment_variables(SlaveNode),
  514. %% start
  515. ok = syn:start(),
  516. ok = syn:init(),
  517. ok = rpc:call(SlaveNode, syn, start, []),
  518. ok = rpc:call(SlaveNode, syn, init, []),
  519. timer:sleep(100),
  520. %% register global process
  521. ResultPid = self(),
  522. global:register_name(syn_register_process_SUITE_result, ResultPid),
  523. %% start processes
  524. PidLocal = syn_test_suite_helper:start_process(),
  525. PidSlave = syn_test_suite_helper:start_process(SlaveNode),
  526. %% register
  527. Meta = {some, meta},
  528. ok = syn:register(<<"local">>, PidLocal, Meta),
  529. ok = syn:register(<<"slave">>, PidSlave),
  530. %% kill process
  531. syn_test_suite_helper:kill_process(PidLocal),
  532. syn_test_suite_helper:kill_process(PidSlave),
  533. %% check callback were triggered
  534. receive
  535. {exited, CurrentNode, <<"local">>, PidLocal, Meta, killed} -> ok
  536. after 2000 ->
  537. ok = registry_process_exit_callback_was_not_called_from_local_node
  538. end,
  539. receive
  540. {exited, SlaveNode, <<"slave">>, PidSlave, undefined, killed} -> ok
  541. after 2000 ->
  542. ok = registry_process_exit_callback_was_not_called_from_slave_node
  543. end,
  544. %% unregister
  545. global:unregister_name(syn_register_process_SUITE_result).
  546. two_nodes_when_mnesia_is_disc_find_by_pid(Config) ->
  547. %% get slave
  548. SlaveNode = proplists:get_value(slave_node, Config),
  549. %% set schema location
  550. application:set_env(mnesia, schema_location, disc),
  551. rpc:call(SlaveNode, mnesia, schema_location, [disc]),
  552. %% create schema
  553. mnesia:create_schema([node(), SlaveNode]),
  554. %% start
  555. ok = syn:start(),
  556. ok = syn:init(),
  557. ok = rpc:call(SlaveNode, syn, start, []),
  558. ok = rpc:call(SlaveNode, syn, init, []),
  559. timer:sleep(100),
  560. %% start process
  561. Pid = syn_test_suite_helper:start_process(),
  562. %% register
  563. ok = syn:register(<<"my proc">>, Pid),
  564. %% retrieve
  565. <<"my proc">> = syn:find_by_pid(Pid),
  566. <<"my proc">> = rpc:call(SlaveNode, syn, find_by_pid, [Pid]),
  567. %% kill process
  568. syn_test_suite_helper:kill_process(Pid),
  569. timer:sleep(100),
  570. %% retrieve
  571. undefined = syn:find_by_pid(Pid),
  572. undefined = rpc:call(SlaveNode, syn, find_by_pid, [Pid]).
  573. %% ===================================================================
  574. %% Internal
  575. %% ===================================================================
  576. registry_process_exit_callback_dummy(Key, Pid, Meta, Reason) ->
  577. global:send(syn_register_process_SUITE_result, {exited, node(), Key, Pid, Meta, Reason}).