syn_register_processes_SUITE.erl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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. single_node_when_mnesia_is_disc_find_by_key(_Config) ->
  366. %% set schema location
  367. application:set_env(mnesia, schema_location, disc),
  368. %% create schema
  369. mnesia:create_schema([node()]),
  370. %% start
  371. ok = syn:start(),
  372. ok = syn:init(),
  373. %% start process
  374. Pid = syn_test_suite_helper:start_process(),
  375. %% retrieve
  376. undefined = syn:find_by_key(<<"my proc">>),
  377. %% register
  378. ok = syn:register(<<"my proc">>, Pid),
  379. %% retrieve
  380. Pid = syn:find_by_key(<<"my proc">>),
  381. %% kill process
  382. syn_test_suite_helper:kill_process(Pid),
  383. timer:sleep(100),
  384. %% retrieve
  385. undefined = syn:find_by_key(<<"my proc">>).
  386. two_nodes_when_mnesia_is_ram_find_by_key(Config) ->
  387. %% get slave
  388. SlaveNode = proplists:get_value(slave_node, Config),
  389. %% set schema location
  390. application:set_env(mnesia, schema_location, ram),
  391. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  392. %% start
  393. ok = syn:start(),
  394. ok = syn:init(),
  395. ok = rpc:call(SlaveNode, syn, start, []),
  396. ok = rpc:call(SlaveNode, syn, init, []),
  397. timer:sleep(100),
  398. %% start process
  399. Pid = syn_test_suite_helper:start_process(),
  400. %% retrieve
  401. undefined = syn:find_by_key(<<"my proc">>),
  402. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]),
  403. %% register
  404. ok = syn:register(<<"my proc">>, Pid),
  405. %% retrieve
  406. Pid = syn:find_by_key(<<"my proc">>),
  407. Pid = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]),
  408. %% kill process
  409. syn_test_suite_helper:kill_process(Pid),
  410. timer:sleep(100),
  411. %% retrieve
  412. undefined = syn:find_by_key(<<"my proc">>),
  413. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc">>]).
  414. two_nodes_when_mnesia_is_ram_find_by_key_with_meta(Config) ->
  415. %% get slave
  416. SlaveNode = proplists:get_value(slave_node, Config),
  417. %% set schema location
  418. application:set_env(mnesia, schema_location, ram),
  419. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  420. %% start
  421. ok = syn:start(),
  422. ok = syn:init(),
  423. ok = rpc:call(SlaveNode, syn, start, []),
  424. ok = rpc:call(SlaveNode, syn, init, []),
  425. timer:sleep(100),
  426. %% start process
  427. Pid1 = syn_test_suite_helper:start_process(),
  428. Pid2 = syn_test_suite_helper:start_process(),
  429. %% retrieve
  430. undefined = syn:find_by_key(<<"my proc 1">>),
  431. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>]),
  432. undefined = syn:find_by_key(<<"my proc 2">>),
  433. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>]),
  434. %% register
  435. Meta = [{some, 1}, {meta, <<"data">>}],
  436. ok = syn:register(<<"my proc 1">>, Pid1, Meta),
  437. ok = syn:register(<<"my proc 2">>, Pid2),
  438. %% retrieve
  439. {Pid1, Meta} = syn:find_by_key(<<"my proc 1">>, with_meta),
  440. {Pid1, Meta} = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>, with_meta]),
  441. {Pid2, undefined} = syn:find_by_key(<<"my proc 2">>, with_meta),
  442. {Pid2, undefined} = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>, with_meta]),
  443. %% kill process
  444. syn_test_suite_helper:kill_process(Pid1),
  445. syn_test_suite_helper:kill_process(Pid2),
  446. timer:sleep(100),
  447. %% retrieve
  448. undefined = syn:find_by_key(<<"my proc 1">>),
  449. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 1">>]),
  450. undefined = syn:find_by_key(<<"my proc 2">>),
  451. undefined = rpc:call(SlaveNode, syn, find_by_key, [<<"my proc 2">>]).
  452. two_nodes_when_mnesia_is_ram_process_count(Config) ->
  453. %% get slave
  454. SlaveNode = proplists:get_value(slave_node, Config),
  455. CurrentNode = node(),
  456. %% set schema location
  457. application:set_env(mnesia, schema_location, ram),
  458. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  459. %% start
  460. ok = syn:start(),
  461. ok = syn:init(),
  462. ok = rpc:call(SlaveNode, syn, start, []),
  463. ok = rpc:call(SlaveNode, syn, init, []),
  464. timer:sleep(100),
  465. %% count
  466. 0 = syn:count(),
  467. 0 = rpc:call(SlaveNode, syn, count, []),
  468. 0 = syn:count(CurrentNode),
  469. 0 = syn:count(SlaveNode),
  470. 0 = rpc:call(SlaveNode, syn, count, [CurrentNode]),
  471. 0 = rpc:call(SlaveNode, syn, count, [SlaveNode]),
  472. %% start processes
  473. PidLocal1 = syn_test_suite_helper:start_process(),
  474. PidLocal2 = syn_test_suite_helper:start_process(),
  475. PidSlave = syn_test_suite_helper:start_process(SlaveNode),
  476. %% register
  477. ok = syn:register(1, PidLocal1),
  478. ok = syn:register(2, PidLocal2),
  479. ok = syn:register(3, PidSlave),
  480. timer:sleep(100),
  481. %% count
  482. 3 = syn:count(),
  483. 3 = rpc:call(SlaveNode, syn, count, []),
  484. 2 = syn:count(CurrentNode),
  485. 1 = syn:count(SlaveNode),
  486. 2 = rpc:call(SlaveNode, syn, count, [CurrentNode]),
  487. 1 = rpc:call(SlaveNode, syn, count, [SlaveNode]),
  488. %% kill processes
  489. syn_test_suite_helper:kill_process(PidLocal1),
  490. syn_test_suite_helper:kill_process(PidLocal2),
  491. syn_test_suite_helper:kill_process(PidSlave),
  492. timer:sleep(100),
  493. %% count
  494. 0 = syn:count(),
  495. 0 = rpc:call(SlaveNode, syn, count, []),
  496. 0 = syn:count(CurrentNode),
  497. 0 = syn:count(SlaveNode),
  498. 0 = rpc:call(SlaveNode, syn, count, [CurrentNode]),
  499. 0 = rpc:call(SlaveNode, syn, count, [SlaveNode]).
  500. two_nodes_when_mnesia_is_ram_callback_on_process_exit(Config) ->
  501. %% get slave
  502. SlaveNode = proplists:get_value(slave_node, Config),
  503. CurrentNode = node(),
  504. %% set schema location
  505. application:set_env(mnesia, schema_location, ram),
  506. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  507. %% load configuration variables from syn-test.config => this defines the callback
  508. syn_test_suite_helper:set_environment_variables(),
  509. syn_test_suite_helper:set_environment_variables(SlaveNode),
  510. %% start
  511. ok = syn:start(),
  512. ok = syn:init(),
  513. ok = rpc:call(SlaveNode, syn, start, []),
  514. ok = rpc:call(SlaveNode, syn, init, []),
  515. timer:sleep(100),
  516. %% register global process
  517. ResultPid = self(),
  518. global:register_name(syn_register_process_SUITE_result, ResultPid),
  519. %% start processes
  520. PidLocal = syn_test_suite_helper:start_process(),
  521. PidSlave = syn_test_suite_helper:start_process(SlaveNode),
  522. %% register
  523. Meta = {some, meta},
  524. ok = syn:register(<<"local">>, PidLocal, Meta),
  525. ok = syn:register(<<"slave">>, PidSlave),
  526. %% kill process
  527. syn_test_suite_helper:kill_process(PidLocal),
  528. syn_test_suite_helper:kill_process(PidSlave),
  529. %% check callback were triggered
  530. receive
  531. {exited, CurrentNode, <<"local">>, PidLocal, Meta, killed} -> ok
  532. after 2000 ->
  533. ok = process_exit_callback_was_not_called_from_local_node
  534. end,
  535. receive
  536. {exited, SlaveNode, <<"slave">>, PidSlave, undefined, killed} -> ok
  537. after 2000 ->
  538. ok = process_exit_callback_was_not_called_from_slave_node
  539. end.
  540. two_nodes_when_mnesia_is_disc_find_by_pid(Config) ->
  541. %% get slave
  542. SlaveNode = proplists:get_value(slave_node, Config),
  543. %% set schema location
  544. application:set_env(mnesia, schema_location, disc),
  545. rpc:call(SlaveNode, mnesia, schema_location, [disc]),
  546. %% create schema
  547. mnesia:create_schema([node(), SlaveNode]),
  548. %% start
  549. ok = syn:start(),
  550. ok = syn:init(),
  551. ok = rpc:call(SlaveNode, syn, start, []),
  552. ok = rpc:call(SlaveNode, syn, init, []),
  553. timer:sleep(100),
  554. %% start process
  555. Pid = syn_test_suite_helper:start_process(),
  556. %% register
  557. ok = syn:register(<<"my proc">>, Pid),
  558. %% retrieve
  559. <<"my proc">> = syn:find_by_pid(Pid),
  560. <<"my proc">> = rpc:call(SlaveNode, syn, find_by_pid, [Pid]),
  561. %% kill process
  562. syn_test_suite_helper:kill_process(Pid),
  563. timer:sleep(100),
  564. %% retrieve
  565. undefined = syn:find_by_pid(Pid),
  566. undefined = rpc:call(SlaveNode, syn, find_by_pid, [Pid]).
  567. %% ===================================================================
  568. %% Internal
  569. %% ===================================================================
  570. process_exit_callback_dummy(Key, Pid, Meta, Reason) ->
  571. global:send(syn_register_process_SUITE_result, {exited, node(), Key, Pid, Meta, Reason}).