syn_register_processes_SUITE.erl 22 KB

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