syn_registry_SUITE.erl 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. %% ==========================================================================================================
  2. %% Syn - A global Process Registry and Process Group manager.
  3. %%
  4. %% The MIT License (MIT)
  5. %%
  6. %% Copyright (c) 2015-2019 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. three_nodes_discover_default_scope/1,
  35. three_nodes_discover_custom_scope/1,
  36. three_nodes_register_unregister_and_monitor_default_scope/1,
  37. three_nodes_register_unregister_and_monitor_custom_scope/1,
  38. three_nodes_cluster_changes_and_conflicts/1
  39. ]).
  40. %% include
  41. -include_lib("common_test/include/ct.hrl").
  42. -include_lib("../src/syn.hrl").
  43. %% ===================================================================
  44. %% Callbacks
  45. %% ===================================================================
  46. %% -------------------------------------------------------------------
  47. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  48. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  49. %% GroupName = atom()
  50. %% TestCase = atom()
  51. %% Reason = any()
  52. %% -------------------------------------------------------------------
  53. all() ->
  54. [
  55. {group, three_nodes_process_registration}
  56. ].
  57. %% -------------------------------------------------------------------
  58. %% Function: groups() -> [Group]
  59. %% Group = {GroupName,Properties,GroupsAndTestCases}
  60. %% GroupName = atom()
  61. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  62. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  63. %% TestCase = atom()
  64. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  65. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  66. %% repeat_until_any_ok | repeat_until_any_fail
  67. %% N = integer() | forever
  68. %% -------------------------------------------------------------------
  69. groups() ->
  70. [
  71. {three_nodes_process_registration, [shuffle], [
  72. %% three_nodes_discover_default_scope,
  73. %% three_nodes_discover_custom_scope,
  74. %% three_nodes_register_unregister_and_monitor_default_scope,
  75. %% three_nodes_register_unregister_and_monitor_custom_scope,
  76. three_nodes_cluster_changes_and_conflicts
  77. ]}
  78. ].
  79. %% -------------------------------------------------------------------
  80. %% Function: init_per_suite(Config0) ->
  81. %% Config1 | {skip,Reason} |
  82. %% {skip_and_save,Reason,Config1}
  83. %% Config0 = Config1 = [tuple()]
  84. %% Reason = any()
  85. %% -------------------------------------------------------------------
  86. init_per_suite(Config) ->
  87. Config.
  88. %% -------------------------------------------------------------------
  89. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  90. %% Config0 = Config1 = [tuple()]
  91. %% -------------------------------------------------------------------
  92. end_per_suite(_Config) ->
  93. ok.
  94. %% -------------------------------------------------------------------
  95. %% Function: init_per_group(GroupName, Config0) ->
  96. %% Config1 | {skip,Reason} |
  97. %% {skip_and_save,Reason,Config1}
  98. %% GroupName = atom()
  99. %% Config0 = Config1 = [tuple()]
  100. %% Reason = any()
  101. %% -------------------------------------------------------------------
  102. init_per_group(three_nodes_process_registration, Config) ->
  103. %% start slave
  104. {ok, SlaveNode1} = syn_test_suite_helper:start_slave(syn_slave_1),
  105. {ok, SlaveNode2} = syn_test_suite_helper:start_slave(syn_slave_2),
  106. %% wait full cluster
  107. case syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1, SlaveNode2]) of
  108. ok ->
  109. %% config
  110. [{slave_node_1, SlaveNode1}, {slave_node_2, SlaveNode2} | Config];
  111. Other ->
  112. ct:pal("*********** Could not get full cluster, skipping"),
  113. end_per_group(three_nodes_process_registration, Config),
  114. {skip, Other}
  115. end;
  116. init_per_group(_GroupName, Config) ->
  117. Config.
  118. %% -------------------------------------------------------------------
  119. %% Function: end_per_group(GroupName, Config0) ->
  120. %% void() | {save_config,Config1}
  121. %% GroupName = atom()
  122. %% Config0 = Config1 = [tuple()]
  123. %% -------------------------------------------------------------------
  124. end_per_group(three_nodes_process_registration, Config) ->
  125. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  126. syn_test_suite_helper:connect_node(SlaveNode1),
  127. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  128. syn_test_suite_helper:connect_node(SlaveNode2),
  129. syn_test_suite_helper:clean_after_test(),
  130. syn_test_suite_helper:stop_slave(syn_slave_1),
  131. syn_test_suite_helper:stop_slave(syn_slave_2),
  132. timer:sleep(1000);
  133. end_per_group(_GroupName, _Config) ->
  134. syn_test_suite_helper:clean_after_test().
  135. %% -------------------------------------------------------------------
  136. %% Function: init_per_testcase(TestCase, Config0) ->
  137. %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
  138. %% TestCase = atom()
  139. %% Config0 = Config1 = [tuple()]
  140. %% Reason = any()
  141. %% -------------------------------------------------------------------
  142. init_per_testcase(TestCase, Config) ->
  143. ct:pal("Starting test: ~p", [TestCase]),
  144. Config.
  145. %% -------------------------------------------------------------------
  146. %% Function: end_per_testcase(TestCase, Config0) ->
  147. %% void() | {save_config,Config1} | {fail,Reason}
  148. %% TestCase = atom()
  149. %% Config0 = Config1 = [tuple()]
  150. %% Reason = any()
  151. %% -------------------------------------------------------------------
  152. end_per_testcase(_, _Config) ->
  153. syn_test_suite_helper:clean_after_test().
  154. %% ===================================================================
  155. %% Tests
  156. %% ===================================================================
  157. three_nodes_discover_default_scope(Config) ->
  158. %% get slaves
  159. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  160. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  161. %% start syn on nodes
  162. ok = syn:start(),
  163. ok = rpc:call(SlaveNode1, syn, start, []),
  164. ok = rpc:call(SlaveNode2, syn, start, []),
  165. timer:sleep(100),
  166. %% check
  167. assert_scope_subcluster(node(), default, [SlaveNode1, SlaveNode2]),
  168. assert_scope_subcluster(SlaveNode1, default, [node(), SlaveNode2]),
  169. assert_scope_subcluster(SlaveNode2, default, [node(), SlaveNode1]),
  170. %% simulate full netsplit
  171. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  172. syn_test_suite_helper:disconnect_node(SlaveNode1),
  173. syn_test_suite_helper:disconnect_node(SlaveNode2),
  174. timer:sleep(100),
  175. %% check
  176. assert_scope_subcluster(node(), default, []),
  177. %% reconnect slave 1
  178. syn_test_suite_helper:connect_node(SlaveNode1),
  179. ok = syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1]),
  180. %% check
  181. assert_scope_subcluster(node(), default, [SlaveNode1]),
  182. assert_scope_subcluster(SlaveNode1, default, [node()]),
  183. %% reconnect all
  184. syn_test_suite_helper:connect_node(SlaveNode2),
  185. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  186. ok = syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1, SlaveNode2]),
  187. %% check
  188. assert_scope_subcluster(node(), default, [SlaveNode1, SlaveNode2]),
  189. assert_scope_subcluster(SlaveNode1, default, [node(), SlaveNode2]),
  190. assert_scope_subcluster(SlaveNode2, default, [node(), SlaveNode1]),
  191. %% crash the scope process on local
  192. syn_test_suite_helper:kill_process(syn_registry_default),
  193. timer:sleep(100),
  194. %% check, it should have rebuilt after supervisor restarts it
  195. assert_scope_subcluster(node(), default, [SlaveNode1, SlaveNode2]),
  196. assert_scope_subcluster(SlaveNode1, default, [node(), SlaveNode2]),
  197. assert_scope_subcluster(SlaveNode2, default, [node(), SlaveNode1]),
  198. %% crash scopes supervisor on local
  199. syn_test_suite_helper:kill_process(syn_scopes_sup),
  200. timer:sleep(100),
  201. %% check
  202. assert_scope_subcluster(node(), default, [SlaveNode1, SlaveNode2]),
  203. assert_scope_subcluster(SlaveNode1, default, [node(), SlaveNode2]),
  204. assert_scope_subcluster(SlaveNode2, default, [node(), SlaveNode1]).
  205. three_nodes_discover_custom_scope(Config) ->
  206. %% get slaves
  207. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  208. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  209. %% start syn on nodes
  210. ok = syn:start(),
  211. ok = rpc:call(SlaveNode1, syn, start, []),
  212. ok = rpc:call(SlaveNode2, syn, start, []),
  213. timer:sleep(100),
  214. %% add custom scopes
  215. ok = syn:add_node_to_scope(custom_scope_ab),
  216. ok = syn:add_node_to_scope(custom_scope_all),
  217. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[custom_scope_ab, custom_scope_bc, custom_scope_all]]),
  218. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[custom_scope_bc, custom_scope_c, custom_scope_all]]),
  219. timer:sleep(100),
  220. %% check
  221. assert_scope_subcluster(node(), custom_scope_ab, [SlaveNode1]),
  222. assert_scope_subcluster(node(), custom_scope_all, [SlaveNode1, SlaveNode2]),
  223. assert_scope_subcluster(SlaveNode1, custom_scope_ab, [node()]),
  224. assert_scope_subcluster(SlaveNode1, custom_scope_bc, [SlaveNode2]),
  225. assert_scope_subcluster(SlaveNode1, custom_scope_all, [node(), SlaveNode2]),
  226. assert_scope_subcluster(SlaveNode2, custom_scope_bc, [SlaveNode1]),
  227. assert_scope_subcluster(SlaveNode2, custom_scope_c, []),
  228. assert_scope_subcluster(SlaveNode2, custom_scope_all, [node(), SlaveNode1]),
  229. %% check default
  230. assert_scope_subcluster(node(), default, [SlaveNode1, SlaveNode2]),
  231. assert_scope_subcluster(SlaveNode1, default, [node(), SlaveNode2]),
  232. assert_scope_subcluster(SlaveNode2, default, [node(), SlaveNode1]),
  233. %% disconnect node 2 (node 1 can still see node 2)
  234. syn_test_suite_helper:disconnect_node(SlaveNode2),
  235. timer:sleep(100),
  236. %% check
  237. assert_scope_subcluster(node(), custom_scope_ab, [SlaveNode1]),
  238. assert_scope_subcluster(node(), custom_scope_all, [SlaveNode1]),
  239. assert_scope_subcluster(SlaveNode1, custom_scope_ab, [node()]),
  240. assert_scope_subcluster(SlaveNode1, custom_scope_bc, [SlaveNode2]),
  241. assert_scope_subcluster(SlaveNode1, custom_scope_all, [node(), SlaveNode2]),
  242. %% reconnect node 2
  243. syn_test_suite_helper:connect_node(SlaveNode2),
  244. ok = syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1, SlaveNode2]),
  245. %% check
  246. assert_scope_subcluster(node(), custom_scope_ab, [SlaveNode1]),
  247. assert_scope_subcluster(node(), custom_scope_all, [SlaveNode1, SlaveNode2]),
  248. assert_scope_subcluster(SlaveNode1, custom_scope_ab, [node()]),
  249. assert_scope_subcluster(SlaveNode1, custom_scope_bc, [SlaveNode2]),
  250. assert_scope_subcluster(SlaveNode1, custom_scope_all, [node(), SlaveNode2]),
  251. assert_scope_subcluster(SlaveNode2, custom_scope_bc, [SlaveNode1]),
  252. assert_scope_subcluster(SlaveNode2, custom_scope_c, []),
  253. assert_scope_subcluster(SlaveNode2, custom_scope_all, [node(), SlaveNode1]),
  254. %% crash a scope process on 2
  255. rpc:call(SlaveNode2, syn_test_suite_helper, kill_process, [syn_registry_custom_scope_bc]),
  256. timer:sleep(100),
  257. %% check
  258. assert_scope_subcluster(node(), custom_scope_ab, [SlaveNode1]),
  259. assert_scope_subcluster(node(), custom_scope_all, [SlaveNode1, SlaveNode2]),
  260. assert_scope_subcluster(SlaveNode1, custom_scope_ab, [node()]),
  261. assert_scope_subcluster(SlaveNode1, custom_scope_bc, [SlaveNode2]),
  262. assert_scope_subcluster(SlaveNode1, custom_scope_all, [node(), SlaveNode2]),
  263. assert_scope_subcluster(SlaveNode2, custom_scope_bc, [SlaveNode1]),
  264. assert_scope_subcluster(SlaveNode2, custom_scope_c, []),
  265. assert_scope_subcluster(SlaveNode2, custom_scope_all, [node(), SlaveNode1]),
  266. %% crash scopes supervisor on local
  267. syn_test_suite_helper:kill_process(syn_scopes_sup),
  268. timer:sleep(100),
  269. %% check
  270. assert_scope_subcluster(node(), custom_scope_ab, [SlaveNode1]),
  271. assert_scope_subcluster(node(), custom_scope_all, [SlaveNode1, SlaveNode2]),
  272. assert_scope_subcluster(SlaveNode1, custom_scope_ab, [node()]),
  273. assert_scope_subcluster(SlaveNode1, custom_scope_bc, [SlaveNode2]),
  274. assert_scope_subcluster(SlaveNode1, custom_scope_all, [node(), SlaveNode2]),
  275. assert_scope_subcluster(SlaveNode2, custom_scope_bc, [SlaveNode1]),
  276. assert_scope_subcluster(SlaveNode2, custom_scope_c, []),
  277. assert_scope_subcluster(SlaveNode2, custom_scope_all, [node(), SlaveNode1]).
  278. three_nodes_register_unregister_and_monitor_default_scope(Config) ->
  279. %% get slaves
  280. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  281. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  282. %% start syn on nodes
  283. ok = syn:start(),
  284. ok = rpc:call(SlaveNode1, syn, start, []),
  285. ok = rpc:call(SlaveNode2, syn, start, []),
  286. timer:sleep(100),
  287. %% start processes
  288. Pid = syn_test_suite_helper:start_process(),
  289. PidWithMeta = syn_test_suite_helper:start_process(),
  290. PidRemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  291. %% retrieve
  292. undefined = syn:lookup(<<"my proc">>),
  293. undefined = rpc:call(SlaveNode1, syn, lookup, [<<"my proc">>]),
  294. undefined = rpc:call(SlaveNode2, syn, lookup, [<<"my proc">>]),
  295. undefined = syn:lookup({"my proc alias"}),
  296. undefined = rpc:call(SlaveNode1, syn, lookup, [{"my proc alias"}]),
  297. undefined = rpc:call(SlaveNode2, syn, lookup, [{"my proc alias"}]),
  298. undefined = syn:lookup(<<"my proc with meta">>),
  299. undefined = rpc:call(SlaveNode1, syn, lookup, [<<"my proc with meta">>]),
  300. undefined = rpc:call(SlaveNode2, syn, lookup, [<<"my proc with meta">>]),
  301. undefined = syn:lookup({remote_pid_on, slave_1}),
  302. undefined = rpc:call(SlaveNode1, syn, lookup, [{remote_pid_on, slave_1}]),
  303. undefined = rpc:call(SlaveNode2, syn, lookup, [{remote_pid_on, slave_1}]),
  304. 0 = syn:registry_count(default),
  305. 0 = syn:registry_count(default, node()),
  306. 0 = syn:registry_count(default, SlaveNode1),
  307. 0 = syn:registry_count(default, SlaveNode2),
  308. %% register
  309. ok = syn:register(<<"my proc">>, Pid),
  310. ok = syn:register({"my proc alias"}, Pid), %% same pid, different name
  311. ok = syn:register(<<"my proc with meta">>, PidWithMeta, {meta, <<"meta">>}), %% pid with meta
  312. ok = syn:register({remote_pid_on, slave_1}, PidRemoteOn1), %% remote on slave 1
  313. timer:sleep(100),
  314. %% errors
  315. {error, taken} = syn:register(<<"my proc">>, PidRemoteOn1),
  316. {error, not_alive} = syn:register({"pid not alive"}, list_to_pid("<0.9999.0>")),
  317. %% retrieve
  318. {Pid, undefined} = syn:lookup(<<"my proc">>),
  319. {Pid, undefined} = rpc:call(SlaveNode1, syn, lookup, [<<"my proc">>]),
  320. {Pid, undefined} = rpc:call(SlaveNode2, syn, lookup, [<<"my proc">>]),
  321. {Pid, undefined} = syn:lookup({"my proc alias"}),
  322. {Pid, undefined} = rpc:call(SlaveNode1, syn, lookup, [{"my proc alias"}]),
  323. {Pid, undefined} = rpc:call(SlaveNode2, syn, lookup, [{"my proc alias"}]),
  324. {PidWithMeta, {meta, <<"meta">>}} = syn:lookup(<<"my proc with meta">>),
  325. {PidWithMeta, {meta, <<"meta">>}} = rpc:call(SlaveNode1, syn, lookup, [<<"my proc with meta">>]),
  326. {PidWithMeta, {meta, <<"meta">>}} = rpc:call(SlaveNode2, syn, lookup, [<<"my proc with meta">>]),
  327. {PidRemoteOn1, undefined} = syn:lookup({remote_pid_on, slave_1}),
  328. {PidRemoteOn1, undefined} = rpc:call(SlaveNode1, syn, lookup, [{remote_pid_on, slave_1}]),
  329. {PidRemoteOn1, undefined} = rpc:call(SlaveNode2, syn, lookup, [{remote_pid_on, slave_1}]),
  330. 4 = syn:registry_count(default),
  331. 3 = syn:registry_count(default, node()),
  332. 1 = syn:registry_count(default, SlaveNode1),
  333. 0 = syn:registry_count(default, SlaveNode2),
  334. %% re-register to edit meta
  335. ok = syn:register(<<"my proc with meta">>, PidWithMeta, {meta2, <<"meta2">>}),
  336. ok = rpc:call(SlaveNode2, syn, register, [{remote_pid_on, slave_1}, PidRemoteOn1, added_meta]), %% updated on slave 2
  337. timer:sleep(100),
  338. %% retrieve
  339. {PidWithMeta, {meta2, <<"meta2">>}} = syn:lookup(<<"my proc with meta">>),
  340. {PidWithMeta, {meta2, <<"meta2">>}} = rpc:call(SlaveNode1, syn, lookup, [<<"my proc with meta">>]),
  341. {PidWithMeta, {meta2, <<"meta2">>}} = rpc:call(SlaveNode2, syn, lookup, [<<"my proc with meta">>]),
  342. {PidRemoteOn1, added_meta} = syn:lookup({remote_pid_on, slave_1}),
  343. {PidRemoteOn1, added_meta} = rpc:call(SlaveNode1, syn, lookup, [{remote_pid_on, slave_1}]),
  344. {PidRemoteOn1, added_meta} = rpc:call(SlaveNode2, syn, lookup, [{remote_pid_on, slave_1}]),
  345. 4 = syn:registry_count(default),
  346. 3 = syn:registry_count(default, node()),
  347. 1 = syn:registry_count(default, SlaveNode1),
  348. 0 = syn:registry_count(default, SlaveNode2),
  349. %% crash scope process to ensure that monitors get recreated
  350. exit(whereis(syn_registry_default), kill),
  351. timer:sleep(100), %$ wait for sup to restart it
  352. %% kill process
  353. syn_test_suite_helper:kill_process(Pid),
  354. syn_test_suite_helper:kill_process(PidRemoteOn1),
  355. %% unregister process
  356. ok = syn:unregister(<<"my proc with meta">>),
  357. timer:sleep(100),
  358. %% retrieve
  359. undefined = syn:lookup(<<"my proc">>),
  360. undefined = rpc:call(SlaveNode1, syn, lookup, [<<"my proc">>]),
  361. undefined = rpc:call(SlaveNode2, syn, lookup, [<<"my proc">>]),
  362. undefined = syn:lookup({"my proc alias"}),
  363. undefined = rpc:call(SlaveNode1, syn, lookup, [{"my proc alias"}]),
  364. undefined = rpc:call(SlaveNode2, syn, lookup, [{"my proc alias"}]),
  365. undefined = syn:lookup(<<"my proc with meta">>),
  366. undefined = rpc:call(SlaveNode1, syn, lookup, [<<"my proc with meta">>]),
  367. undefined = rpc:call(SlaveNode2, syn, lookup, [<<"my proc with meta">>]),
  368. undefined = syn:lookup({remote_pid_on, slave_1}),
  369. undefined = rpc:call(SlaveNode1, syn, lookup, [{remote_pid_on, slave_1}]),
  370. undefined = rpc:call(SlaveNode2, syn, lookup, [{remote_pid_on, slave_1}]),
  371. 0 = syn:registry_count(default),
  372. 0 = syn:registry_count(default, node()),
  373. 0 = syn:registry_count(default, SlaveNode1),
  374. 0 = syn:registry_count(default, SlaveNode2),
  375. %% errors
  376. {error, undefined} = syn:unregister({invalid_name}),
  377. %% (simulate race condition)
  378. Pid1 = syn_test_suite_helper:start_process(),
  379. Pid2 = syn_test_suite_helper:start_process(),
  380. ok = syn:register(<<"my proc">>, Pid1),
  381. timer:sleep(100),
  382. syn_registry:remove_from_local_table(default, <<"my proc">>, Pid1),
  383. syn_registry:add_to_local_table(default, <<"my proc">>, Pid2, undefined, 0, undefined),
  384. {error, race_condition} = rpc:call(SlaveNode1, syn, unregister, [<<"my proc">>]).
  385. three_nodes_register_unregister_and_monitor_custom_scope(Config) ->
  386. %% get slaves
  387. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  388. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  389. %% start syn on nodes
  390. ok = syn:start(),
  391. ok = rpc:call(SlaveNode1, syn, start, []),
  392. ok = rpc:call(SlaveNode2, syn, start, []),
  393. timer:sleep(100),
  394. %% add custom scopes
  395. ok = syn:add_node_to_scope(custom_scope_ab),
  396. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[custom_scope_ab, custom_scope_bc]]),
  397. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[custom_scope_bc]]),
  398. timer:sleep(100),
  399. %% start processes
  400. Pid = syn_test_suite_helper:start_process(),
  401. PidWithMeta = syn_test_suite_helper:start_process(),
  402. PidRemoteWithMetaOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  403. %% retrieve
  404. undefined = syn:lookup("scope_a"),
  405. undefined = syn:lookup("scope_a"),
  406. undefined = rpc:call(SlaveNode1, syn, lookup, ["scope_a"]),
  407. undefined = syn:lookup(custom_scope_ab, "scope_a"),
  408. undefined = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a"]),
  409. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a"]),
  410. undefined = syn:lookup(custom_scope_ab, "scope_a_alias"),
  411. undefined = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  412. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  413. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, {remote_scoped_bc}),
  414. undefined = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, {remote_scoped_bc}]),
  415. undefined = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, {remote_scoped_bc}]),
  416. 0 = syn:registry_count(custom_scope_ab),
  417. 0 = syn:registry_count(custom_scope_ab, node()),
  418. 0 = syn:registry_count(custom_scope_ab, SlaveNode1),
  419. 0 = syn:registry_count(custom_scope_ab, SlaveNode2),
  420. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc),
  421. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, node()),
  422. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, SlaveNode1),
  423. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, SlaveNode2),
  424. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab]),
  425. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, node()]),
  426. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, SlaveNode1]),
  427. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, SlaveNode2]),
  428. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc]),
  429. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, node()]),
  430. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  431. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  432. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab]),
  433. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, node()]),
  434. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, SlaveNode1]),
  435. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, SlaveNode2]),
  436. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc]),
  437. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, node()]),
  438. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  439. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  440. %% register
  441. ok = syn:register(custom_scope_ab, "scope_a", Pid),
  442. ok = syn:register(custom_scope_ab, "scope_a_alias", PidWithMeta, <<"with_meta">>),
  443. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:register(custom_scope_bc, "scope_a", Pid),
  444. {'EXIT', {{invalid_scope, non_existent_scope}, _}} = catch syn:register(non_existent_scope, "scope_a", Pid),
  445. ok = rpc:call(SlaveNode2, syn, register, [custom_scope_bc, {remote_scoped_bc}, PidRemoteWithMetaOn1, <<"with_meta 1">>]),
  446. timer:sleep(100),
  447. %% errors
  448. {error, taken} = syn:register(custom_scope_ab, "scope_a", PidWithMeta),
  449. {error, not_alive} = syn:register(custom_scope_ab, {"pid not alive"}, list_to_pid("<0.9999.0>")),
  450. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:register(custom_scope_bc, "scope_a_noscope", Pid),
  451. %% retrieve
  452. undefined = syn:lookup("scope_a"),
  453. undefined = syn:lookup("scope_a"),
  454. undefined = rpc:call(SlaveNode1, syn, lookup, ["scope_a"]),
  455. {Pid, undefined} = syn:lookup(custom_scope_ab, "scope_a"),
  456. {Pid, undefined} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a"]),
  457. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a"]),
  458. {PidWithMeta, <<"with_meta">>} = syn:lookup(custom_scope_ab, "scope_a_alias"),
  459. {PidWithMeta, <<"with_meta">>} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  460. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  461. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, {remote_scoped_bc}),
  462. {PidRemoteWithMetaOn1, <<"with_meta 1">>} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, {remote_scoped_bc}]),
  463. {PidRemoteWithMetaOn1, <<"with_meta 1">>} = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, {remote_scoped_bc}]),
  464. 2 = syn:registry_count(custom_scope_ab),
  465. 2 = syn:registry_count(custom_scope_ab, node()),
  466. 0 = syn:registry_count(custom_scope_ab, SlaveNode1),
  467. 0 = syn:registry_count(custom_scope_ab, SlaveNode2),
  468. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc),
  469. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, node()),
  470. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, SlaveNode1),
  471. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, SlaveNode2),
  472. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab]),
  473. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, node()]),
  474. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, SlaveNode1]),
  475. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, SlaveNode2]),
  476. 1 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc]),
  477. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, node()]),
  478. 1 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  479. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  480. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab]),
  481. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, node()]),
  482. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, SlaveNode1]),
  483. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, SlaveNode2]),
  484. 1 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc]),
  485. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, node()]),
  486. 1 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  487. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  488. %% re-register to edit meta
  489. ok = syn:register(custom_scope_ab, "scope_a_alias", PidWithMeta, <<"with_meta_updated">>),
  490. timer:sleep(100),
  491. {PidWithMeta, <<"with_meta_updated">>} = syn:lookup(custom_scope_ab, "scope_a_alias"),
  492. {PidWithMeta, <<"with_meta_updated">>} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  493. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  494. %% crash scope process to ensure that monitors get recreated
  495. exit(whereis(syn_registry_custom_scope_ab), kill),
  496. timer:sleep(100), %$ wait for sup to restart it
  497. %% kill process
  498. syn_test_suite_helper:kill_process(Pid),
  499. syn_test_suite_helper:kill_process(PidWithMeta),
  500. %% unregister processes
  501. {error, undefined} = catch syn:unregister(<<"my proc with meta">>),
  502. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:unregister(custom_scope_bc, <<"my proc with meta">>),
  503. ok = rpc:call(SlaveNode1, syn, unregister, [custom_scope_bc, {remote_scoped_bc}]),
  504. timer:sleep(100),
  505. %% retrieve
  506. undefined = syn:lookup("scope_a"),
  507. undefined = syn:lookup("scope_a"),
  508. undefined = rpc:call(SlaveNode1, syn, lookup, ["scope_a"]),
  509. undefined = syn:lookup(custom_scope_ab, "scope_a"),
  510. undefined = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a"]),
  511. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a"]),
  512. undefined = syn:lookup(custom_scope_ab, "scope_a_alias"),
  513. undefined = rpc:call(SlaveNode1, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  514. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [custom_scope_ab, "scope_a_alias"]),
  515. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, {remote_scoped_bc}),
  516. undefined = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, {remote_scoped_bc}]),
  517. undefined = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, {remote_scoped_bc}]),
  518. 0 = syn:registry_count(custom_scope_ab),
  519. 0 = syn:registry_count(custom_scope_ab, node()),
  520. 0 = syn:registry_count(custom_scope_ab, SlaveNode1),
  521. 0 = syn:registry_count(custom_scope_ab, SlaveNode2),
  522. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc),
  523. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, node()),
  524. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, SlaveNode1),
  525. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc, SlaveNode2),
  526. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab]),
  527. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, node()]),
  528. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, SlaveNode1]),
  529. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_ab, SlaveNode2]),
  530. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc]),
  531. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, node()]),
  532. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  533. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  534. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab]),
  535. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, node()]),
  536. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, SlaveNode1]),
  537. {badrpc, {'EXIT', {{invalid_scope, custom_scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [custom_scope_ab, SlaveNode2]),
  538. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc]),
  539. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, node()]),
  540. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  541. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  542. %% errors
  543. {error, undefined} = syn:unregister(custom_scope_ab, {invalid_name}),
  544. %% (simulate race condition)
  545. Pid1 = syn_test_suite_helper:start_process(),
  546. Pid2 = syn_test_suite_helper:start_process(),
  547. ok = syn:register(custom_scope_ab, <<"my proc">>, Pid1),
  548. timer:sleep(100),
  549. syn_registry:remove_from_local_table(custom_scope_ab, <<"my proc">>, Pid1),
  550. syn_registry:add_to_local_table(custom_scope_ab, <<"my proc">>, Pid2, undefined, 0, undefined),
  551. {error, race_condition} = rpc:call(SlaveNode1, syn, unregister, [custom_scope_ab, <<"my proc">>]).
  552. three_nodes_cluster_changes_and_conflicts(Config) ->
  553. %% get slaves
  554. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  555. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  556. %% disconnect 1 from 2
  557. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  558. %% start syn on 1 and 2, nodes don't know of each other
  559. ok = rpc:call(SlaveNode1, syn, start, []),
  560. ok = rpc:call(SlaveNode2, syn, start, []),
  561. %% add custom scopes
  562. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[custom_scope_bc]]),
  563. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[custom_scope_bc]]),
  564. timer:sleep(100),
  565. %% start processes
  566. PidRemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  567. PidRemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  568. %% register
  569. ok = rpc:call(SlaveNode1, syn, register, ["proc-1", PidRemoteOn1, "meta-1"]),
  570. ok = rpc:call(SlaveNode1, syn, register, ["proc-2", PidRemoteOn2, "meta-2"]),
  571. ok = rpc:call(SlaveNode1, syn, register, [custom_scope_bc, "BC-proc-1", PidRemoteOn1, "meta-1"]),
  572. ok = rpc:call(SlaveNode1, syn, register, [custom_scope_bc, "BC-proc-1 alias", PidRemoteOn1, "meta-1 alias"]),
  573. timer:sleep(100),
  574. %% form full cluster
  575. ok = syn:start(),
  576. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  577. syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1, SlaveNode2]),
  578. %% retrieve
  579. {PidRemoteOn1, "meta-1"} = syn:lookup("proc-1"),
  580. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode1, syn, lookup, ["proc-1"]),
  581. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode2, syn, lookup, ["proc-1"]),
  582. {PidRemoteOn2, "meta-2"} = syn:lookup("proc-2"),
  583. {PidRemoteOn2, "meta-2"} = rpc:call(SlaveNode1, syn, lookup, ["proc-2"]),
  584. {PidRemoteOn2, "meta-2"} = rpc:call(SlaveNode2, syn, lookup, ["proc-2"]),
  585. 2 = syn:registry_count(default),
  586. 0 = syn:registry_count(default, node()),
  587. 1 = syn:registry_count(default, SlaveNode1),
  588. 1 = syn:registry_count(default, SlaveNode2),
  589. 2 = rpc:call(SlaveNode1, syn, registry_count, [default]),
  590. 0 = rpc:call(SlaveNode1, syn, registry_count, [default, node()]),
  591. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode1]),
  592. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode2]),
  593. 2 = rpc:call(SlaveNode2, syn, registry_count, [default]),
  594. 0 = rpc:call(SlaveNode2, syn, registry_count, [default, node()]),
  595. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode1]),
  596. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode2]),
  597. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, "BC-proc-1"),
  598. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, "BC-proc-1"]),
  599. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, "BC-proc-1"]),
  600. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, "BC-proc-1 alias"),
  601. {PidRemoteOn1, "meta-1 alias"} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, "BC-proc-1 alias"]),
  602. {PidRemoteOn1, "meta-1 alias"} = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, "BC-proc-1 alias"]),
  603. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc),
  604. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc]),
  605. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, node()]),
  606. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  607. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  608. 2 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc]),
  609. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, node()]),
  610. 2 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  611. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  612. %% partial netsplit (1 cannot see 2)
  613. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  614. timer:sleep(100),
  615. %% retrieve
  616. {PidRemoteOn1, "meta-1"} = syn:lookup("proc-1"),
  617. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode1, syn, lookup, ["proc-1"]),
  618. undefined = rpc:call(SlaveNode2, syn, lookup, ["proc-1"]),
  619. {PidRemoteOn2, "meta-2"} = syn:lookup("proc-2"),
  620. undefined = rpc:call(SlaveNode1, syn, lookup, ["proc-2"]),
  621. {PidRemoteOn2, "meta-2"} = rpc:call(SlaveNode2, syn, lookup, ["proc-2"]),
  622. 2 = syn:registry_count(default),
  623. 0 = syn:registry_count(default, node()),
  624. 1 = syn:registry_count(default, SlaveNode1),
  625. 1 = syn:registry_count(default, SlaveNode2),
  626. 1 = rpc:call(SlaveNode1, syn, registry_count, [default]),
  627. 0 = rpc:call(SlaveNode1, syn, registry_count, [default, node()]),
  628. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode1]),
  629. 0 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode2]),
  630. 1 = rpc:call(SlaveNode2, syn, registry_count, [default]),
  631. 0 = rpc:call(SlaveNode2, syn, registry_count, [default, node()]),
  632. 0 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode1]),
  633. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode2]),
  634. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, "BC-proc-1"),
  635. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, "BC-proc-1"]),
  636. undefined = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, "BC-proc-1"]),
  637. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, "BC-proc-1 alias"),
  638. {PidRemoteOn1, "meta-1 alias"} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, "BC-proc-1 alias"]),
  639. undefined = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, "BC-proc-1 alias"]),
  640. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc),
  641. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc]),
  642. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, node()]),
  643. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  644. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  645. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc]),
  646. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, node()]),
  647. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  648. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  649. %% re-join
  650. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  651. syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1, SlaveNode2]),
  652. %% retrieve
  653. {PidRemoteOn1, "meta-1"} = syn:lookup("proc-1"),
  654. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode1, syn, lookup, ["proc-1"]),
  655. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode2, syn, lookup, ["proc-1"]),
  656. {PidRemoteOn2, "meta-2"} = syn:lookup("proc-2"),
  657. {PidRemoteOn2, "meta-2"} = rpc:call(SlaveNode1, syn, lookup, ["proc-2"]),
  658. {PidRemoteOn2, "meta-2"} = rpc:call(SlaveNode2, syn, lookup, ["proc-2"]),
  659. 2 = syn:registry_count(default),
  660. 0 = syn:registry_count(default, node()),
  661. 1 = syn:registry_count(default, SlaveNode1),
  662. 1 = syn:registry_count(default, SlaveNode2),
  663. 2 = rpc:call(SlaveNode1, syn, registry_count, [default]),
  664. 0 = rpc:call(SlaveNode1, syn, registry_count, [default, node()]),
  665. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode1]),
  666. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode2]),
  667. 2 = rpc:call(SlaveNode2, syn, registry_count, [default]),
  668. 0 = rpc:call(SlaveNode2, syn, registry_count, [default, node()]),
  669. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode1]),
  670. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode2]),
  671. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, "BC-proc-1"),
  672. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, "BC-proc-1"]),
  673. {PidRemoteOn1, "meta-1"} = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, "BC-proc-1"]),
  674. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:lookup(custom_scope_bc, "BC-proc-1 alias"),
  675. {PidRemoteOn1, "meta-1 alias"} = rpc:call(SlaveNode1, syn, lookup, [custom_scope_bc, "BC-proc-1 alias"]),
  676. {PidRemoteOn1, "meta-1 alias"} = rpc:call(SlaveNode2, syn, lookup, [custom_scope_bc, "BC-proc-1 alias"]),
  677. {'EXIT', {{invalid_scope, custom_scope_bc}, _}} = catch syn:registry_count(custom_scope_bc),
  678. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc]),
  679. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, node()]),
  680. 2 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  681. 0 = rpc:call(SlaveNode1, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  682. 2 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc]),
  683. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, node()]),
  684. 2 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode1]),
  685. 0 = rpc:call(SlaveNode2, syn, registry_count, [custom_scope_bc, SlaveNode2]),
  686. %% partial netsplit (1 cannot see 2)
  687. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  688. timer:sleep(100),
  689. %% start conflict processes
  690. Pid2RemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  691. Pid2RemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  692. ct:pal("STARTED On1: ~p, On2: ~p", [Pid2RemoteOn1, Pid2RemoteOn2]),
  693. %% register conflicts new during netsplit
  694. ok = rpc:call(SlaveNode1, syn, register, ["proc-2", Pid2RemoteOn1, "new-meta-2"]),
  695. ok = rpc:call(SlaveNode2, syn, register, ["proc-1", Pid2RemoteOn2, "new-meta-1"]),
  696. %% re-join
  697. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  698. syn_test_suite_helper:wait_cluster_connected([node(), SlaveNode1, SlaveNode2]),
  699. %% retrieve
  700. {Pid2RemoteOn2, "new-meta-1"} = syn:lookup("proc-1"),
  701. {Pid2RemoteOn2, "new-meta-1"} = rpc:call(SlaveNode1, syn, lookup, ["proc-1"]),
  702. {Pid2RemoteOn2, "new-meta-1"} = rpc:call(SlaveNode2, syn, lookup, ["proc-1"]),
  703. {Pid2RemoteOn1, "new-meta-2"} = syn:lookup("proc-2"),
  704. {Pid2RemoteOn1, "new-meta-2"} = rpc:call(SlaveNode1, syn, lookup, ["proc-2"]),
  705. {Pid2RemoteOn1, "new-meta-2"} = rpc:call(SlaveNode2, syn, lookup, ["proc-2"]),
  706. 2 = syn:registry_count(default),
  707. 0 = syn:registry_count(default, node()),
  708. 1 = syn:registry_count(default, SlaveNode1),
  709. 1 = syn:registry_count(default, SlaveNode2),
  710. 2 = rpc:call(SlaveNode1, syn, registry_count, [default]),
  711. 0 = rpc:call(SlaveNode1, syn, registry_count, [default, node()]),
  712. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode1]),
  713. 1 = rpc:call(SlaveNode1, syn, registry_count, [default, SlaveNode2]),
  714. 2 = rpc:call(SlaveNode2, syn, registry_count, [default]),
  715. 0 = rpc:call(SlaveNode2, syn, registry_count, [default, node()]),
  716. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode1]),
  717. 1 = rpc:call(SlaveNode2, syn, registry_count, [default, SlaveNode2]).
  718. %% ===================================================================
  719. %% Internal
  720. %% ===================================================================
  721. assert_scope_subcluster(Node, Scope, ExpectedNodes) ->
  722. NodesMap = rpc:call(Node, syn_registry, get_subcluster_nodes, [Scope]),
  723. Nodes = maps:keys(NodesMap),
  724. ExpectedCount = length(ExpectedNodes),
  725. ExpectedCount = length(Nodes),
  726. lists:foreach(fun(RemoteNode) -> true = lists:member(RemoteNode, Nodes) end, ExpectedNodes).