syn_registry_SUITE.erl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. {error, taken} = syn:register(<<"my proc">>, Pid2),
  275. %% retrieve
  276. Pid = syn:find_by_key(<<"my proc">>),
  277. %% kill process
  278. syn_test_suite_helper:kill_process(Pid),
  279. timer:sleep(100),
  280. %% retrieve
  281. undefined = syn:find_by_key(<<"my proc">>),
  282. %% reuse
  283. ok = syn:register(<<"my proc">>, Pid2),
  284. %% retrieve
  285. Pid2 = syn:find_by_key(<<"my proc">>),
  286. %% kill process
  287. syn_test_suite_helper:kill_process(Pid),
  288. timer:sleep(100),
  289. %% retrieve
  290. undefined = syn:find_by_pid(Pid).
  291. single_node_when_mnesia_is_ram_unregister(_Config) ->
  292. %% set schema location
  293. application:set_env(mnesia, schema_location, ram),
  294. %% start
  295. ok = syn:start(),
  296. ok = syn:init(),
  297. %% start process
  298. Pid = syn_test_suite_helper:start_process(),
  299. %% unregister
  300. {error, undefined} = syn:unregister(<<"my proc">>),
  301. %% register
  302. ok = syn:register(<<"my proc">>, Pid),
  303. %% retrieve
  304. Pid = syn:find_by_key(<<"my proc">>),
  305. %% unregister
  306. ok = syn:unregister(<<"my proc">>),
  307. %% retrieve
  308. undefined = syn:find_by_key(<<"my proc">>),
  309. undefined = syn:find_by_pid(Pid),
  310. %% kill process
  311. syn_test_suite_helper:kill_process(Pid).
  312. single_node_when_mnesia_is_ram_process_count(_Config) ->
  313. %% set schema location
  314. application:set_env(mnesia, schema_location, ram),
  315. %% start
  316. ok = syn:start(),
  317. ok = syn:init(),
  318. %% count
  319. 0 = syn:registry_count(),
  320. %% start process
  321. Pid1 = syn_test_suite_helper:start_process(),
  322. Pid2 = syn_test_suite_helper:start_process(),
  323. Pid3 = syn_test_suite_helper:start_process(),
  324. %% register
  325. ok = syn:register(1, Pid1),
  326. ok = syn:register(2, Pid2),
  327. ok = syn:register(3, Pid3),
  328. %% count
  329. 3 = syn:registry_count(),
  330. %% kill processes
  331. syn_test_suite_helper:kill_process(Pid1),
  332. syn_test_suite_helper:kill_process(Pid2),
  333. syn_test_suite_helper:kill_process(Pid3),
  334. timer:sleep(100),
  335. %% count
  336. 0 = syn:registry_count().
  337. single_node_when_mnesia_is_ram_callback_on_process_exit(_Config) ->
  338. CurrentNode = node(),
  339. %% set schema location
  340. application:set_env(mnesia, schema_location, ram),
  341. %% load configuration variables from syn-test.config => this defines the callback
  342. syn_test_suite_helper:set_environment_variables(),
  343. %% start
  344. ok = syn:start(),
  345. ok = syn:init(),
  346. %% register global process
  347. ResultPid = self(),
  348. global:register_name(syn_register_process_SUITE_result, ResultPid),
  349. %% start process
  350. Pid = syn_test_suite_helper:start_process(),
  351. %% register
  352. Meta = {some, meta},
  353. ok = syn:register(<<"my proc">>, Pid, Meta),
  354. %% kill process
  355. syn_test_suite_helper:kill_process(Pid),
  356. %% check callback were triggered
  357. receive
  358. {exited, CurrentNode, <<"my proc">>, Pid, Meta, killed} -> ok
  359. after 2000 ->
  360. ok = registry_process_exit_callback_was_not_called_from_local_node
  361. end,
  362. %% unregister
  363. global:unregister_name(syn_register_process_SUITE_result).
  364. single_node_when_mnesia_is_disc_find_by_key(_Config) ->
  365. %% set schema location
  366. application:set_env(mnesia, schema_location, disc),
  367. %% create schema
  368. mnesia:create_schema([node()]),
  369. %% start
  370. ok = syn:start(),
  371. ok = syn:init(),
  372. %% start process
  373. Pid = syn_test_suite_helper:start_process(),
  374. %% retrieve
  375. undefined = syn:find_by_key(<<"my proc">>),
  376. %% register
  377. ok = syn:register(<<"my proc">>, Pid),
  378. %% retrieve
  379. Pid = syn:find_by_key(<<"my proc">>),
  380. %% kill process
  381. syn_test_suite_helper:kill_process(Pid),
  382. timer:sleep(100),
  383. %% retrieve
  384. undefined = syn:find_by_key(<<"my proc">>).
  385. two_nodes_when_mnesia_is_ram_find_by_key(Config) ->
  386. %% get slave
  387. SlaveNode = proplists:get_value(slave_node, Config),
  388. %% set schema location
  389. application:set_env(mnesia, schema_location, ram),
  390. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  391. %% start
  392. ok = syn:start(),
  393. ok = syn:init(),
  394. ok = rpc:call(SlaveNode, syn, start, []),
  395. ok = rpc:call(SlaveNode, syn, init, []),
  396. timer:sleep(100),
  397. %% start process
  398. Pid = syn_test_suite_helper:start_process(),
  399. %% retrieve
  400. undefined = syn:find_by_key(<<"my proc">>),
  401. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]),
  402. %% register
  403. ok = syn:register(<<"my proc">>, Pid),
  404. %% retrieve
  405. Pid = syn:find_by_key(<<"my proc">>),
  406. Pid = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]),
  407. %% kill process
  408. syn_test_suite_helper:kill_process(Pid),
  409. timer:sleep(100),
  410. %% retrieve
  411. undefined = syn:find_by_key(<<"my proc">>),
  412. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]).
  413. two_nodes_when_mnesia_is_ram_find_by_key_with_meta(Config) ->
  414. %% get slave
  415. SlaveNode = proplists:get_value(slave_node, Config),
  416. %% set schema location
  417. application:set_env(mnesia, schema_location, ram),
  418. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  419. %% start
  420. ok = syn:start(),
  421. ok = syn:init(),
  422. ok = rpc:call(SlaveNode, syn, start, []),
  423. ok = rpc:call(SlaveNode, syn, init, []),
  424. timer:sleep(100),
  425. %% start process
  426. Pid1 = syn_test_suite_helper:start_process(),
  427. Pid2 = syn_test_suite_helper:start_process(),
  428. %% retrieve
  429. undefined = syn:find_by_key(<<"my proc 1">>),
  430. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>]),
  431. undefined = syn:find_by_key(<<"my proc 2">>),
  432. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>]),
  433. %% register
  434. Meta = [{some, 1}, {meta, <<"data">>}],
  435. ok = syn:register(<<"my proc 1">>, Pid1, Meta),
  436. ok = syn:register(<<"my proc 2">>, Pid2),
  437. %% retrieve
  438. {Pid1, Meta} = syn:find_by_key(<<"my proc 1">>, with_meta),
  439. {Pid1, Meta} = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>, with_meta]),
  440. {Pid2, undefined} = syn:find_by_key(<<"my proc 2">>, with_meta),
  441. {Pid2, undefined} = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>, with_meta]),
  442. %% kill process
  443. syn_test_suite_helper:kill_process(Pid1),
  444. syn_test_suite_helper:kill_process(Pid2),
  445. timer:sleep(100),
  446. %% retrieve
  447. undefined = syn:find_by_key(<<"my proc 1">>),
  448. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>]),
  449. undefined = syn:find_by_key(<<"my proc 2">>),
  450. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>]).
  451. two_nodes_when_mnesia_is_ram_process_count(Config) ->
  452. %% get slave
  453. SlaveNode = proplists:get_value(slave_node, Config),
  454. CurrentNode = node(),
  455. %% set schema location
  456. application:set_env(mnesia, schema_location, ram),
  457. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  458. %% start
  459. ok = syn:start(),
  460. ok = syn:init(),
  461. ok = rpc:call(SlaveNode, syn, start, []),
  462. ok = rpc:call(SlaveNode, syn, init, []),
  463. timer:sleep(100),
  464. %% count
  465. 0 = syn:registry_count(),
  466. 0 = rpc:call(SlaveNode, syn, registry_count, []),
  467. 0 = syn:registry_count(CurrentNode),
  468. 0 = syn:registry_count(SlaveNode),
  469. 0 = rpc:call(SlaveNode, syn, registry_count, [CurrentNode]),
  470. 0 = rpc:call(SlaveNode, syn, registry_count, [SlaveNode]),
  471. %% start processes
  472. PidLocal1 = syn_test_suite_helper:start_process(),
  473. PidLocal2 = syn_test_suite_helper:start_process(),
  474. PidSlave = syn_test_suite_helper:start_process(SlaveNode),
  475. %% register
  476. ok = syn:register(1, PidLocal1),
  477. ok = syn:register(2, PidLocal2),
  478. ok = syn:register(3, PidSlave),
  479. timer:sleep(100),
  480. %% count
  481. 3 = syn:registry_count(),
  482. 3 = rpc:call(SlaveNode, syn, registry_count, []),
  483. 2 = syn:registry_count(CurrentNode),
  484. 1 = syn:registry_count(SlaveNode),
  485. 2 = rpc:call(SlaveNode, syn, registry_count, [CurrentNode]),
  486. 1 = rpc:call(SlaveNode, syn, registry_count, [SlaveNode]),
  487. %% kill processes
  488. syn_test_suite_helper:kill_process(PidLocal1),
  489. syn_test_suite_helper:kill_process(PidLocal2),
  490. syn_test_suite_helper:kill_process(PidSlave),
  491. timer:sleep(100),
  492. %% count
  493. 0 = syn:registry_count(),
  494. 0 = rpc:call(SlaveNode, syn, registry_count, []),
  495. 0 = syn:registry_count(CurrentNode),
  496. 0 = syn:registry_count(SlaveNode),
  497. 0 = rpc:call(SlaveNode, syn, registry_count, [CurrentNode]),
  498. 0 = rpc:call(SlaveNode, syn, registry_count, [SlaveNode]).
  499. two_nodes_when_mnesia_is_ram_callback_on_process_exit(Config) ->
  500. %% get slave
  501. SlaveNode = proplists:get_value(slave_node, Config),
  502. CurrentNode = node(),
  503. %% set schema location
  504. application:set_env(mnesia, schema_location, ram),
  505. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  506. %% load configuration variables from syn-test.config => this defines the callback
  507. syn_test_suite_helper:set_environment_variables(),
  508. syn_test_suite_helper:set_environment_variables(SlaveNode),
  509. %% start
  510. ok = syn:start(),
  511. ok = syn:init(),
  512. ok = rpc:call(SlaveNode, syn, start, []),
  513. ok = rpc:call(SlaveNode, syn, init, []),
  514. timer:sleep(100),
  515. %% register global process
  516. ResultPid = self(),
  517. global:register_name(syn_register_process_SUITE_result, ResultPid),
  518. %% start processes
  519. PidLocal = syn_test_suite_helper:start_process(),
  520. PidSlave = syn_test_suite_helper:start_process(SlaveNode),
  521. %% register
  522. Meta = {some, meta},
  523. ok = syn:register(<<"local">>, PidLocal, Meta),
  524. ok = syn:register(<<"slave">>, PidSlave),
  525. %% kill process
  526. syn_test_suite_helper:kill_process(PidLocal),
  527. syn_test_suite_helper:kill_process(PidSlave),
  528. %% check callback were triggered
  529. receive
  530. {exited, CurrentNode, <<"local">>, PidLocal, Meta, killed} -> ok
  531. after 2000 ->
  532. ok = registry_process_exit_callback_was_not_called_from_local_node
  533. end,
  534. receive
  535. {exited, SlaveNode, <<"slave">>, PidSlave, undefined, killed} -> ok
  536. after 2000 ->
  537. ok = registry_process_exit_callback_was_not_called_from_slave_node
  538. end,
  539. %% unregister
  540. global:unregister_name(syn_register_process_SUITE_result).
  541. two_nodes_when_mnesia_is_disc_find_by_pid(Config) ->
  542. %% get slave
  543. SlaveNode = proplists:get_value(slave_node, Config),
  544. %% set schema location
  545. application:set_env(mnesia, schema_location, disc),
  546. rpc:call(SlaveNode, mnesia, schema_location, [disc]),
  547. %% create schema
  548. mnesia:create_schema([node(), SlaveNode]),
  549. %% start
  550. ok = syn:start(),
  551. ok = syn:init(),
  552. ok = rpc:call(SlaveNode, syn, start, []),
  553. ok = rpc:call(SlaveNode, syn, init, []),
  554. timer:sleep(100),
  555. %% start process
  556. Pid = syn_test_suite_helper:start_process(),
  557. %% register
  558. ok = syn:register(<<"my proc">>, Pid),
  559. %% retrieve
  560. <<"my proc">> = syn:find_by_pid(Pid),
  561. <<"my proc">> = rpc:call(SlaveNode, syn, find_by_pid, [Pid]),
  562. %% kill process
  563. syn_test_suite_helper:kill_process(Pid),
  564. timer:sleep(100),
  565. %% retrieve
  566. undefined = syn:find_by_pid(Pid),
  567. undefined = rpc:call(SlaveNode, syn, find_by_pid, [Pid]).
  568. %% ===================================================================
  569. %% Internal
  570. %% ===================================================================
  571. registry_process_exit_callback_dummy(Key, Pid, Meta, Reason) ->
  572. global:send(syn_register_process_SUITE_result, {exited, node(), Key, Pid, Meta, Reason}).