syn_registry_SUITE.erl 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. %% ==========================================================================================================
  2. %% Syn - A global Process Registry and Process Group manager.
  3. %%
  4. %% The MIT License (MIT)
  5. %%
  6. %% Copyright (c) 2015-2021 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. one_node_via_register_unregister/1
  35. ]).
  36. -export([
  37. three_nodes_discover/1,
  38. three_nodes_register_unregister_and_monitor/1,
  39. three_nodes_register_filter_unknown_node/1,
  40. three_nodes_cluster_changes/1,
  41. three_nodes_cluster_conflicts/1,
  42. three_nodes_custom_event_handler_reg_unreg/1,
  43. three_nodes_custom_event_handler_conflict_resolution/1
  44. ]).
  45. %% include
  46. -include_lib("common_test/include/ct.hrl").
  47. -include_lib("syn/src/syn.hrl").
  48. %% ===================================================================
  49. %% Callbacks
  50. %% ===================================================================
  51. %% -------------------------------------------------------------------
  52. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  53. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  54. %% GroupName = atom()
  55. %% TestCase = atom()
  56. %% Reason = any()
  57. %% -------------------------------------------------------------------
  58. all() ->
  59. [
  60. {group, one_node_process_registration},
  61. {group, three_nodes_process_registration}
  62. ].
  63. %% -------------------------------------------------------------------
  64. %% Function: groups() -> [Group]
  65. %% Group = {GroupName,Properties,GroupsAndTestCases}
  66. %% GroupName = atom()
  67. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  68. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  69. %% TestCase = atom()
  70. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  71. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  72. %% repeat_until_any_ok | repeat_until_any_fail
  73. %% N = integer() | forever
  74. %% -------------------------------------------------------------------
  75. groups() ->
  76. [
  77. {one_node_process_registration, [shuffle], [
  78. one_node_via_register_unregister
  79. ]},
  80. {three_nodes_process_registration, [shuffle], [
  81. three_nodes_discover,
  82. three_nodes_register_unregister_and_monitor,
  83. three_nodes_register_filter_unknown_node,
  84. three_nodes_cluster_changes,
  85. three_nodes_cluster_conflicts,
  86. three_nodes_custom_event_handler_reg_unreg,
  87. three_nodes_custom_event_handler_conflict_resolution
  88. ]}
  89. ].
  90. %% -------------------------------------------------------------------
  91. %% Function: init_per_suite(Config0) ->
  92. %% Config1 | {skip,Reason} |
  93. %% {skip_and_save,Reason,Config1}
  94. %% Config0 = Config1 = [tuple()]
  95. %% Reason = any()
  96. %% -------------------------------------------------------------------
  97. init_per_suite(Config) ->
  98. Config.
  99. %% -------------------------------------------------------------------
  100. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  101. %% Config0 = Config1 = [tuple()]
  102. %% -------------------------------------------------------------------
  103. end_per_suite(_Config) ->
  104. ok.
  105. %% -------------------------------------------------------------------
  106. %% Function: init_per_group(GroupName, Config0) ->
  107. %% Config1 | {skip,Reason} |
  108. %% {skip_and_save,Reason,Config1}
  109. %% GroupName = atom()
  110. %% Config0 = Config1 = [tuple()]
  111. %% Reason = any()
  112. %% -------------------------------------------------------------------
  113. init_per_group(three_nodes_process_registration, Config) ->
  114. %% start slave
  115. {ok, SlaveNode1} = syn_test_suite_helper:start_slave(syn_slave_1),
  116. {ok, SlaveNode2} = syn_test_suite_helper:start_slave(syn_slave_2),
  117. syn_test_suite_helper:connect_node(SlaveNode1),
  118. syn_test_suite_helper:connect_node(SlaveNode2),
  119. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  120. %% wait full cluster
  121. case syn_test_suite_helper:wait_cluster_mesh_connected([node(), SlaveNode1, SlaveNode2]) of
  122. ok ->
  123. %% config
  124. [{slave_node_1, SlaveNode1}, {slave_node_2, SlaveNode2} | Config];
  125. Other ->
  126. ct:pal("*********** Could not get full cluster, skipping"),
  127. end_per_group(three_nodes_process_registration, Config),
  128. {skip, Other}
  129. end;
  130. init_per_group(_GroupName, Config) ->
  131. Config.
  132. %% -------------------------------------------------------------------
  133. %% Function: end_per_group(GroupName, Config0) ->
  134. %% void() | {save_config,Config1}
  135. %% GroupName = atom()
  136. %% Config0 = Config1 = [tuple()]
  137. %% -------------------------------------------------------------------
  138. end_per_group(three_nodes_process_registration, Config) ->
  139. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  140. syn_test_suite_helper:connect_node(SlaveNode1),
  141. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  142. syn_test_suite_helper:connect_node(SlaveNode2),
  143. syn_test_suite_helper:clean_after_test(),
  144. syn_test_suite_helper:stop_slave(syn_slave_1),
  145. syn_test_suite_helper:stop_slave(syn_slave_2),
  146. timer:sleep(1000);
  147. end_per_group(_GroupName, _Config) ->
  148. syn_test_suite_helper:clean_after_test().
  149. %% -------------------------------------------------------------------
  150. %% Function: init_per_testcase(TestCase, Config0) ->
  151. %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
  152. %% TestCase = atom()
  153. %% Config0 = Config1 = [tuple()]
  154. %% Reason = any()
  155. %% -------------------------------------------------------------------
  156. init_per_testcase(TestCase, Config) ->
  157. ct:pal("Starting test: ~p", [TestCase]),
  158. Config.
  159. %% -------------------------------------------------------------------
  160. %% Function: end_per_testcase(TestCase, Config0) ->
  161. %% void() | {save_config,Config1} | {fail,Reason}
  162. %% TestCase = atom()
  163. %% Config0 = Config1 = [tuple()]
  164. %% Reason = any()
  165. %% -------------------------------------------------------------------
  166. end_per_testcase(_, _Config) ->
  167. syn_test_suite_helper:clean_after_test().
  168. %% ===================================================================
  169. %% Tests
  170. %% ===================================================================
  171. one_node_via_register_unregister(_Config) ->
  172. %% start syn
  173. ok = syn:start(),
  174. %% ---> scope
  175. syn:add_node_to_scopes([scope]),
  176. %% start gen server via syn
  177. GenServerNameCustom = {scope, <<"my proc">>},
  178. TupleCustom = {via, syn, GenServerNameCustom},
  179. {ok, PidCustom} = syn_test_gen_server:start_link(TupleCustom),
  180. %% retrieve
  181. {PidCustom, undefined} = syn:lookup(scope, <<"my proc">>),
  182. %% call
  183. pong = syn_test_gen_server:ping(TupleCustom),
  184. %% send via syn
  185. syn:send(GenServerNameCustom, {self(), send_ping}),
  186. syn_test_suite_helper:assert_received_messages([
  187. reply_pong
  188. ]),
  189. %% stop server
  190. syn_test_gen_server:stop(TupleCustom),
  191. %% retrieve
  192. syn_test_suite_helper:assert_wait(
  193. undefined,
  194. fun() -> syn:lookup(scope, <<"my proc">>) end
  195. ),
  196. %% send via syn
  197. {badarg, {GenServerNameCustom, anything}} = catch syn:send(GenServerNameCustom, anything).
  198. three_nodes_discover(Config) ->
  199. %% get slaves
  200. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  201. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  202. %% start syn on nodes
  203. ok = syn:start(),
  204. ok = rpc:call(SlaveNode1, syn, start, []),
  205. ok = rpc:call(SlaveNode2, syn, start, []),
  206. %% add scopes
  207. ok = syn:add_node_to_scopes([scope_ab]),
  208. ok = syn:add_node_to_scopes([scope_all]),
  209. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_ab, scope_bc, scope_all]]),
  210. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_bc, scope_c, scope_all]]),
  211. %% subcluster_nodes should return invalid errors
  212. {'EXIT', {{invalid_scope, custom_abcdef}, _}} = catch syn_registry:subcluster_nodes(custom_abcdef),
  213. %% check
  214. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_ab, [SlaveNode1]),
  215. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_all, [SlaveNode1, SlaveNode2]),
  216. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_ab, [node()]),
  217. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_bc, [SlaveNode2]),
  218. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_all, [node(), SlaveNode2]),
  219. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_bc, [SlaveNode1]),
  220. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_c, []),
  221. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_all, [node(), SlaveNode1]),
  222. %% disconnect node 2 (node 1 can still see node 2)
  223. syn_test_suite_helper:disconnect_node(SlaveNode2),
  224. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1]),
  225. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  226. %% check
  227. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_ab, [SlaveNode1]),
  228. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_all, [SlaveNode1]),
  229. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_ab, [node()]),
  230. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_bc, [SlaveNode2]),
  231. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_all, [node(), SlaveNode2]),
  232. %% reconnect node 2
  233. syn_test_suite_helper:connect_node(SlaveNode2),
  234. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  235. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  236. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  237. %% check
  238. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_ab, [SlaveNode1]),
  239. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_all, [SlaveNode1, SlaveNode2]),
  240. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_ab, [node()]),
  241. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_bc, [SlaveNode2]),
  242. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_all, [node(), SlaveNode2]),
  243. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_bc, [SlaveNode1]),
  244. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_c, []),
  245. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_all, [node(), SlaveNode1]),
  246. %% crash a scope process on 2
  247. rpc:call(SlaveNode2, syn_test_suite_helper, kill_process, [syn_registry_scope_bc]),
  248. rpc:call(SlaveNode2, syn_test_suite_helper, wait_process_name_ready, [syn_registry_default]),
  249. %% check
  250. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_ab, [SlaveNode1]),
  251. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_all, [SlaveNode1, SlaveNode2]),
  252. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_ab, [node()]),
  253. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_bc, [SlaveNode2]),
  254. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_all, [node(), SlaveNode2]),
  255. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_bc, [SlaveNode1]),
  256. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_c, []),
  257. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_all, [node(), SlaveNode1]),
  258. %% crash scopes supervisor on local
  259. syn_test_suite_helper:kill_process(syn_scopes_sup),
  260. syn_test_suite_helper:wait_process_name_ready(syn_registry_scope_ab),
  261. syn_test_suite_helper:wait_process_name_ready(syn_registry_scope_all),
  262. %% check
  263. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_ab, [SlaveNode1]),
  264. syn_test_suite_helper:assert_registry_scope_subcluster(node(), scope_all, [SlaveNode1, SlaveNode2]),
  265. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_ab, [node()]),
  266. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_bc, [SlaveNode2]),
  267. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode1, scope_all, [node(), SlaveNode2]),
  268. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_bc, [SlaveNode1]),
  269. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_c, []),
  270. syn_test_suite_helper:assert_registry_scope_subcluster(SlaveNode2, scope_all, [node(), SlaveNode1]).
  271. three_nodes_register_unregister_and_monitor(Config) ->
  272. %% get slaves
  273. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  274. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  275. %% start syn on nodes
  276. ok = syn:start(),
  277. ok = rpc:call(SlaveNode1, syn, start, []),
  278. ok = rpc:call(SlaveNode2, syn, start, []),
  279. %% add scopes
  280. ok = syn:add_node_to_scopes([scope_ab]),
  281. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_ab, scope_bc]]),
  282. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_bc]]),
  283. %% start processes
  284. Pid = syn_test_suite_helper:start_process(),
  285. PidWithMeta = syn_test_suite_helper:start_process(),
  286. PidRemoteWithMetaOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  287. %% retrieve
  288. undefined = syn:lookup(scope_ab, "scope_a"),
  289. undefined = rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a"]),
  290. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a"]),
  291. undefined = syn:lookup(scope_ab, "scope_a_alias"),
  292. undefined = rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a_alias"]),
  293. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a_alias"]),
  294. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, {remote_scoped_bc}),
  295. undefined = rpc:call(SlaveNode1, syn, lookup, [scope_bc, {remote_scoped_bc}]),
  296. undefined = rpc:call(SlaveNode2, syn, lookup, [scope_bc, {remote_scoped_bc}]),
  297. 0 = syn:registry_count(scope_ab),
  298. 0 = syn:registry_count(scope_ab, node()),
  299. 0 = syn:registry_count(scope_ab, SlaveNode1),
  300. 0 = syn:registry_count(scope_ab, SlaveNode2),
  301. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  302. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, node()),
  303. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode1),
  304. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode2),
  305. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab]),
  306. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, node()]),
  307. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode1]),
  308. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode2]),
  309. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  310. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  311. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  312. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  313. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab]),
  314. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, node()]),
  315. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode1]),
  316. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode2]),
  317. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  318. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  319. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  320. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  321. %% register
  322. ok = syn:register(scope_ab, "scope_a", Pid),
  323. ok = syn:register(scope_ab, "scope_a_alias", PidWithMeta, <<"with_meta">>),
  324. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:register(scope_bc, "scope_a", Pid),
  325. {'EXIT', {{invalid_scope, non_existent_scope}, _}} = catch syn:register(non_existent_scope, "scope_a", Pid),
  326. ok = rpc:call(SlaveNode2, syn, register, [scope_bc, {remote_scoped_bc}, PidRemoteWithMetaOn1, <<"with_meta 1">>]),
  327. %% errors
  328. {error, taken} = syn:register(scope_ab, "scope_a", PidWithMeta),
  329. {error, not_alive} = syn:register(scope_ab, {"pid not alive"}, list_to_pid("<0.9999.0>")),
  330. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:register(scope_bc, "scope_a_noscope", Pid),
  331. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:unregister(scope_bc, "scope_a_noscope"),
  332. {badrpc, {'EXIT', {{invalid_remote_scope, scope_bc}, _}}} = catch rpc:call(SlaveNode1, syn, register, [scope_bc, "pid-outside", Pid]),
  333. %% retrieve
  334. syn_test_suite_helper:assert_wait(
  335. {Pid, undefined},
  336. fun() -> syn:lookup(scope_ab, "scope_a") end
  337. ),
  338. syn_test_suite_helper:assert_wait(
  339. {Pid, undefined},
  340. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a"]) end
  341. ),
  342. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a"]),
  343. syn_test_suite_helper:assert_wait(
  344. {PidWithMeta, <<"with_meta">>},
  345. fun() -> syn:lookup(scope_ab, "scope_a_alias") end
  346. ),
  347. syn_test_suite_helper:assert_wait(
  348. {PidWithMeta, <<"with_meta">>},
  349. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a_alias"]) end
  350. ),
  351. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a_alias"]),
  352. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, {remote_scoped_bc}),
  353. syn_test_suite_helper:assert_wait(
  354. {PidRemoteWithMetaOn1, <<"with_meta 1">>},
  355. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, {remote_scoped_bc}]) end
  356. ),
  357. syn_test_suite_helper:assert_wait(
  358. {PidRemoteWithMetaOn1, <<"with_meta 1">>},
  359. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, {remote_scoped_bc}]) end
  360. ),
  361. 2 = syn:registry_count(scope_ab),
  362. 2 = syn:registry_count(scope_ab, node()),
  363. 0 = syn:registry_count(scope_ab, SlaveNode1),
  364. 0 = syn:registry_count(scope_ab, SlaveNode2),
  365. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  366. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, node()),
  367. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode1),
  368. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode2),
  369. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab]),
  370. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, node()]),
  371. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode1]),
  372. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode2]),
  373. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  374. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  375. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  376. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  377. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab]),
  378. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, node()]),
  379. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode1]),
  380. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode2]),
  381. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  382. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  383. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  384. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  385. %% re-register to edit meta
  386. ok = syn:register(scope_ab, "scope_a_alias", PidWithMeta, <<"with_meta_updated">>),
  387. syn_test_suite_helper:assert_wait(
  388. {PidWithMeta, <<"with_meta_updated">>},
  389. fun() -> syn:lookup(scope_ab, "scope_a_alias") end
  390. ),
  391. syn_test_suite_helper:assert_wait(
  392. {PidWithMeta, <<"with_meta_updated">>},
  393. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a_alias"]) end
  394. ),
  395. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a_alias"]),
  396. %% register remote
  397. syn:register(scope_ab, "ab_on_1", PidRemoteWithMetaOn1, <<"ab-on-1">>),
  398. syn_test_suite_helper:assert_wait(
  399. {PidRemoteWithMetaOn1, <<"ab-on-1">>},
  400. fun() -> syn:lookup(scope_ab, "ab_on_1") end
  401. ),
  402. %% crash scope process to ensure that monitors get recreated & data received from other nodes
  403. syn_test_suite_helper:kill_process(syn_registry_scope_ab),
  404. syn_test_suite_helper:wait_process_name_ready(syn_registry_scope_ab),
  405. %% check remote has been sync'ed back
  406. syn_test_suite_helper:assert_wait(
  407. {PidRemoteWithMetaOn1, <<"ab-on-1">>},
  408. fun() -> syn:lookup(scope_ab, "ab_on_1") end
  409. ),
  410. %% kill process
  411. syn_test_suite_helper:kill_process(Pid),
  412. syn_test_suite_helper:kill_process(PidWithMeta),
  413. %% unregister processes
  414. {error, undefined} = catch syn:unregister(scope_ab, <<"my proc with meta">>),
  415. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:unregister(scope_bc, <<"my proc with meta">>),
  416. ok = rpc:call(SlaveNode1, syn, unregister, [scope_bc, {remote_scoped_bc}]),
  417. %% retrieve
  418. syn_test_suite_helper:assert_wait(
  419. undefined,
  420. fun() -> syn:lookup(scope_ab, "scope_a") end
  421. ),
  422. syn_test_suite_helper:assert_wait(
  423. undefined,
  424. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a"]) end
  425. ),
  426. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a"]),
  427. syn_test_suite_helper:assert_wait(
  428. undefined,
  429. fun() -> syn:lookup(scope_ab, "scope_a_alias") end
  430. ),
  431. syn_test_suite_helper:assert_wait(
  432. undefined,
  433. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a_alias"]) end
  434. ),
  435. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a_alias"]),
  436. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, {remote_scoped_bc}),
  437. syn_test_suite_helper:assert_wait(
  438. undefined,
  439. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, {remote_scoped_bc}]) end
  440. ),
  441. syn_test_suite_helper:assert_wait(
  442. undefined,
  443. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, {remote_scoped_bc}]) end
  444. ),
  445. 1 = syn:registry_count(scope_ab),
  446. 0 = syn:registry_count(scope_ab, node()),
  447. 1 = syn:registry_count(scope_ab, SlaveNode1),
  448. 0 = syn:registry_count(scope_ab, SlaveNode2),
  449. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  450. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, node()),
  451. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode1),
  452. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode2),
  453. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab]),
  454. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, node()]),
  455. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode1]),
  456. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode2]),
  457. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  458. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  459. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  460. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  461. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab]),
  462. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, node()]),
  463. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode1]),
  464. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode2]),
  465. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  466. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  467. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  468. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  469. %% errors
  470. {error, undefined} = syn:unregister(scope_ab, {invalid_name}),
  471. %% (simulate race condition)
  472. Pid1 = syn_test_suite_helper:start_process(),
  473. Pid2 = syn_test_suite_helper:start_process(),
  474. ok = syn:register(scope_ab, <<"my proc">>, Pid1),
  475. syn_test_suite_helper:assert_wait(
  476. {Pid1, undefined},
  477. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, <<"my proc">>]) end
  478. ),
  479. remove_from_local_table(scope_ab, <<"my proc">>, Pid1),
  480. add_to_local_table(scope_ab, <<"my proc">>, Pid2, undefined, 0, undefined),
  481. {error, race_condition} = rpc:call(SlaveNode1, syn, unregister, [scope_ab, <<"my proc">>]).
  482. three_nodes_register_filter_unknown_node(Config) ->
  483. %% get slaves
  484. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  485. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  486. %% start syn on 1 and 2
  487. ok = rpc:call(SlaveNode1, syn, start, []),
  488. ok = rpc:call(SlaveNode2, syn, start, []),
  489. %% add scopes
  490. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_bc]]),
  491. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_bc]]),
  492. %% send sync message from out of scope node
  493. InvalidPid = syn_test_suite_helper:start_process(),
  494. {syn_registry_scope_bc, SlaveNode1} ! {'3.0', sync_register, <<"proc-name">>, InvalidPid, undefined, os:system_time(millisecond), normal},
  495. %% check
  496. undefined = rpc:call(SlaveNode1, syn, lookup, [scope_bc, <<"proc-name">>]).
  497. three_nodes_cluster_changes(Config) ->
  498. %% get slaves
  499. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  500. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  501. %% disconnect 1 from 2
  502. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  503. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  504. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  505. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  506. %% start syn on 1 and 2, nodes don't know of each other
  507. ok = rpc:call(SlaveNode1, syn, start, []),
  508. ok = rpc:call(SlaveNode2, syn, start, []),
  509. %% add scopes
  510. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  511. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  512. %% start processes
  513. PidRemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  514. PidRemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  515. %% register
  516. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-1", PidRemoteOn1, "meta-1"]),
  517. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-2", PidRemoteOn2, "meta-2"]),
  518. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "BC-proc-1", PidRemoteOn1, "meta-1"]),
  519. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "BC-proc-1 alias", PidRemoteOn1, "meta-1 alias"]),
  520. %% form full cluster
  521. ok = syn:start(),
  522. ok = syn:add_node_to_scopes([scope_all]),
  523. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  524. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  525. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  526. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  527. %% retrieve
  528. syn_test_suite_helper:assert_wait(
  529. {PidRemoteOn1, "meta-1"},
  530. fun() -> syn:lookup(scope_all, "proc-1") end
  531. ),
  532. syn_test_suite_helper:assert_wait(
  533. {PidRemoteOn1, "meta-1"},
  534. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-1"]) end
  535. ),
  536. syn_test_suite_helper:assert_wait(
  537. {PidRemoteOn1, "meta-1"},
  538. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-1"]) end
  539. ),
  540. syn_test_suite_helper:assert_wait(
  541. {PidRemoteOn2, "meta-2"},
  542. fun() -> syn:lookup(scope_all, "proc-2") end
  543. ),
  544. syn_test_suite_helper:assert_wait(
  545. {PidRemoteOn2, "meta-2"},
  546. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-2"]) end
  547. ),
  548. syn_test_suite_helper:assert_wait(
  549. {PidRemoteOn2, "meta-2"},
  550. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-2"]) end
  551. ),
  552. 2 = syn:registry_count(scope_all),
  553. 0 = syn:registry_count(scope_all, node()),
  554. 1 = syn:registry_count(scope_all, SlaveNode1),
  555. 1 = syn:registry_count(scope_all, SlaveNode2),
  556. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  557. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  558. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  559. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  560. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  561. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  562. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  563. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  564. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1"),
  565. syn_test_suite_helper:assert_wait(
  566. {PidRemoteOn1, "meta-1"},
  567. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1"]) end
  568. ),
  569. syn_test_suite_helper:assert_wait(
  570. {PidRemoteOn1, "meta-1"},
  571. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1"]) end
  572. ),
  573. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1 alias"),
  574. syn_test_suite_helper:assert_wait(
  575. {PidRemoteOn1, "meta-1 alias"},
  576. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  577. ),
  578. syn_test_suite_helper:assert_wait(
  579. {PidRemoteOn1, "meta-1 alias"},
  580. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  581. ),
  582. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  583. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, node()),
  584. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode1),
  585. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode2),
  586. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  587. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  588. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  589. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  590. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  591. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  592. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  593. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  594. %% partial netsplit (1 cannot see 2)
  595. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  596. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  597. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  598. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  599. %% retrieve
  600. syn_test_suite_helper:assert_wait(
  601. {PidRemoteOn1, "meta-1"},
  602. fun() -> syn:lookup(scope_all, "proc-1") end
  603. ),
  604. syn_test_suite_helper:assert_wait(
  605. {PidRemoteOn1, "meta-1"},
  606. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-1"]) end
  607. ),
  608. syn_test_suite_helper:assert_wait(
  609. undefined,
  610. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-1"]) end
  611. ),
  612. syn_test_suite_helper:assert_wait(
  613. {PidRemoteOn2, "meta-2"},
  614. fun() -> syn:lookup(scope_all, "proc-2") end
  615. ),
  616. syn_test_suite_helper:assert_wait(
  617. undefined,
  618. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-2"]) end
  619. ),
  620. syn_test_suite_helper:assert_wait(
  621. {PidRemoteOn2, "meta-2"},
  622. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-2"]) end
  623. ),
  624. 2 = syn:registry_count(scope_all),
  625. 0 = syn:registry_count(scope_all, node()),
  626. 1 = syn:registry_count(scope_all, SlaveNode1),
  627. 1 = syn:registry_count(scope_all, SlaveNode2),
  628. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  629. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  630. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  631. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  632. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  633. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  634. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  635. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  636. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1"),
  637. syn_test_suite_helper:assert_wait(
  638. {PidRemoteOn1, "meta-1"},
  639. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1"]) end
  640. ),
  641. syn_test_suite_helper:assert_wait(
  642. undefined,
  643. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1"]) end
  644. ),
  645. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1 alias"),
  646. syn_test_suite_helper:assert_wait(
  647. {PidRemoteOn1, "meta-1 alias"},
  648. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  649. ),
  650. syn_test_suite_helper:assert_wait(
  651. undefined,
  652. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  653. ),
  654. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  655. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  656. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  657. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  658. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  659. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  660. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  661. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  662. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  663. %% re-join
  664. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  665. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  666. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  667. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  668. %% retrieve
  669. syn_test_suite_helper:assert_wait(
  670. {PidRemoteOn1, "meta-1"},
  671. fun() -> syn:lookup(scope_all, "proc-1") end
  672. ),
  673. syn_test_suite_helper:assert_wait(
  674. {PidRemoteOn1, "meta-1"},
  675. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-1"]) end
  676. ),
  677. syn_test_suite_helper:assert_wait(
  678. {PidRemoteOn1, "meta-1"},
  679. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-1"]) end
  680. ),
  681. syn_test_suite_helper:assert_wait(
  682. {PidRemoteOn2, "meta-2"},
  683. fun() -> syn:lookup(scope_all, "proc-2") end
  684. ),
  685. syn_test_suite_helper:assert_wait(
  686. {PidRemoteOn2, "meta-2"},
  687. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-2"]) end
  688. ),
  689. syn_test_suite_helper:assert_wait(
  690. {PidRemoteOn2, "meta-2"},
  691. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-2"]) end
  692. ),
  693. 2 = syn:registry_count(scope_all),
  694. 0 = syn:registry_count(scope_all, node()),
  695. 1 = syn:registry_count(scope_all, SlaveNode1),
  696. 1 = syn:registry_count(scope_all, SlaveNode2),
  697. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  698. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  699. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  700. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  701. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  702. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  703. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  704. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  705. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1"),
  706. syn_test_suite_helper:assert_wait(
  707. {PidRemoteOn1, "meta-1"},
  708. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1"]) end
  709. ),
  710. syn_test_suite_helper:assert_wait(
  711. {PidRemoteOn1, "meta-1"},
  712. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1"]) end
  713. ),
  714. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1 alias"),
  715. syn_test_suite_helper:assert_wait(
  716. {PidRemoteOn1, "meta-1 alias"},
  717. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  718. ),
  719. syn_test_suite_helper:assert_wait(
  720. {PidRemoteOn1, "meta-1 alias"},
  721. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  722. ),
  723. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  724. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  725. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  726. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  727. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  728. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  729. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  730. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  731. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]).
  732. three_nodes_cluster_conflicts(Config) ->
  733. %% get slaves
  734. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  735. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  736. %% start syn on nodes
  737. ok = syn:start(),
  738. ok = rpc:call(SlaveNode1, syn, start, []),
  739. ok = rpc:call(SlaveNode2, syn, start, []),
  740. %% add scopes
  741. ok = syn:add_node_to_scopes([scope_all]),
  742. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  743. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  744. %% partial netsplit (1 cannot see 2)
  745. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  746. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  747. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  748. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  749. %% start conflict processes
  750. Pid2RemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  751. Pid2RemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  752. %% --> conflict by netsplit
  753. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit", Pid2RemoteOn1, "meta-1"]),
  754. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit", Pid2RemoteOn2, "meta-2"]),
  755. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped", Pid2RemoteOn1, "meta-1"]),
  756. ok = rpc:call(SlaveNode2, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped", Pid2RemoteOn2, "meta-2"]),
  757. %% re-join
  758. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  759. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  760. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  761. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  762. %% retrieve
  763. syn_test_suite_helper:assert_wait(
  764. {Pid2RemoteOn2, "meta-2"},
  765. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit") end
  766. ),
  767. syn_test_suite_helper:assert_wait(
  768. {Pid2RemoteOn2, "meta-2"},
  769. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit"]) end
  770. ),
  771. syn_test_suite_helper:assert_wait(
  772. {Pid2RemoteOn2, "meta-2"},
  773. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit"]) end
  774. ),
  775. 1 = syn:registry_count(scope_all),
  776. 0 = syn:registry_count(scope_all, node()),
  777. 0 = syn:registry_count(scope_all, SlaveNode1),
  778. 1 = syn:registry_count(scope_all, SlaveNode2),
  779. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  780. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  781. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  782. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  783. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  784. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  785. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  786. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  787. syn_test_suite_helper:assert_wait(
  788. {Pid2RemoteOn2, "meta-2"},
  789. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped"]) end
  790. ),
  791. syn_test_suite_helper:assert_wait(
  792. {Pid2RemoteOn2, "meta-2"},
  793. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped"]) end
  794. ),
  795. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  796. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  797. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  798. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  799. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  800. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  801. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  802. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  803. %% process alive
  804. syn_test_suite_helper:assert_wait(
  805. false,
  806. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [Pid2RemoteOn1]) end
  807. ),
  808. syn_test_suite_helper:assert_wait(
  809. true,
  810. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [Pid2RemoteOn2]) end
  811. ),
  812. %% --> conflict by race condition
  813. PidOnMaster = syn_test_suite_helper:start_process(),
  814. PidOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  815. rpc:call(SlaveNode1, syn_registry, add_to_local_table,
  816. [default, <<"my proc">>, PidOn1, "meta-2", erlang:system_time(), undefined]
  817. ),
  818. ok = syn:register(scope_all, <<"my proc">>, PidOnMaster, "meta-1"),
  819. %% retrieve
  820. syn_test_suite_helper:assert_wait(
  821. {PidOnMaster, "meta-1"},
  822. fun() -> syn:lookup(scope_all, <<"my proc">>) end
  823. ),
  824. syn_test_suite_helper:assert_wait(
  825. {PidOnMaster, "meta-1"},
  826. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, <<"my proc">>]) end
  827. ),
  828. syn_test_suite_helper:assert_wait(
  829. {PidOnMaster, "meta-1"},
  830. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, <<"my proc">>]) end
  831. ).
  832. %% NB: we can't check for process alive here because we injected the conflicting process in the DB
  833. %% -> it's not actually monitored
  834. three_nodes_custom_event_handler_reg_unreg(Config) ->
  835. %% get slaves
  836. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  837. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  838. %% add custom handler for callbacks
  839. syn:set_event_handler(syn_test_event_handler_callbacks),
  840. rpc:call(SlaveNode1, syn, set_event_handler, [syn_test_event_handler_callbacks]),
  841. rpc:call(SlaveNode2, syn, set_event_handler, [syn_test_event_handler_callbacks]),
  842. %% start syn on nodes
  843. ok = syn:start(),
  844. ok = rpc:call(SlaveNode1, syn, start, []),
  845. ok = rpc:call(SlaveNode2, syn, start, []),
  846. %% add scopes
  847. ok = syn:add_node_to_scopes([scope_all]),
  848. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all]]),
  849. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all]]),
  850. %% init
  851. LocalNode = node(),
  852. %% start process
  853. Pid = syn_test_suite_helper:start_process(),
  854. Pid2 = syn_test_suite_helper:start_process(),
  855. %% ---> on registration
  856. ok = syn:register(scope_all, "proc-handler", Pid, {recipient, self(), <<"meta">>}),
  857. %% check callbacks called
  858. syn_test_suite_helper:assert_received_messages([
  859. {on_process_registered, LocalNode, scope_all, "proc-handler", Pid, <<"meta">>, normal},
  860. {on_process_registered, SlaveNode1, scope_all, "proc-handler", Pid, <<"meta">>, normal},
  861. {on_process_registered, SlaveNode2, scope_all, "proc-handler", Pid, <<"meta">>, normal}
  862. ]),
  863. syn_test_suite_helper:assert_empty_queue(self()),
  864. %% registration from another node
  865. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-handler-2", Pid2, {recipient, self(), <<"meta-for-2">>}]),
  866. %% check callbacks called
  867. syn_test_suite_helper:assert_received_messages([
  868. {on_process_registered, LocalNode, scope_all, "proc-handler-2", Pid2, <<"meta-for-2">>, normal},
  869. {on_process_registered, SlaveNode1, scope_all, "proc-handler-2", Pid2, <<"meta-for-2">>, normal},
  870. {on_process_registered, SlaveNode2, scope_all, "proc-handler-2", Pid2, <<"meta-for-2">>, normal}
  871. ]),
  872. syn_test_suite_helper:assert_empty_queue(self()),
  873. %% ---> on meta update
  874. ok = syn:register(scope_all, "proc-handler", Pid, {recipient, self(), <<"new-meta">>}),
  875. %% check callbacks called
  876. syn_test_suite_helper:assert_received_messages([
  877. {on_registry_process_updated, LocalNode, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  878. {on_registry_process_updated, SlaveNode1, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  879. {on_registry_process_updated, SlaveNode2, scope_all, "proc-handler", Pid, <<"new-meta">>, normal}
  880. ]),
  881. syn_test_suite_helper:assert_empty_queue(self()),
  882. %% meta update from another node
  883. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-handler-2", Pid2, {recipient, self(), <<"meta-for-2-update">>}]),
  884. %% check callbacks called
  885. syn_test_suite_helper:assert_received_messages([
  886. {on_registry_process_updated, LocalNode, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  887. {on_registry_process_updated, SlaveNode1, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  888. {on_registry_process_updated, SlaveNode2, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal}
  889. ]),
  890. syn_test_suite_helper:assert_empty_queue(self()),
  891. %% ---> on unregister
  892. ok = syn:unregister(scope_all, "proc-handler"),
  893. %% check callbacks called
  894. syn_test_suite_helper:assert_received_messages([
  895. {on_process_unregistered, LocalNode, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  896. {on_process_unregistered, SlaveNode1, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  897. {on_process_unregistered, SlaveNode2, scope_all, "proc-handler", Pid, <<"new-meta">>, normal}
  898. ]),
  899. syn_test_suite_helper:assert_empty_queue(self()),
  900. %% unregister from another node
  901. ok = rpc:call(SlaveNode1, syn, unregister, [scope_all, "proc-handler-2"]),
  902. %% check callbacks called
  903. syn_test_suite_helper:assert_received_messages([
  904. {on_process_unregistered, LocalNode, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  905. {on_process_unregistered, SlaveNode1, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  906. {on_process_unregistered, SlaveNode2, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal}
  907. ]),
  908. syn_test_suite_helper:assert_empty_queue(self()),
  909. %% clean & check
  910. syn_test_suite_helper:kill_process(Pid),
  911. syn_test_suite_helper:assert_empty_queue(self()),
  912. %% ---> after a netsplit
  913. PidRemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  914. syn:register(scope_all, remote_on_1, PidRemoteOn1, {recipient, self(), <<"netsplit">>}),
  915. %% check callbacks called
  916. syn_test_suite_helper:assert_received_messages([
  917. {on_process_registered, LocalNode, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, normal},
  918. {on_process_registered, SlaveNode1, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, normal},
  919. {on_process_registered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, normal}
  920. ]),
  921. syn_test_suite_helper:assert_empty_queue(self()),
  922. %% partial netsplit (1 cannot see 2)
  923. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  924. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  925. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  926. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  927. %% check callbacks called
  928. syn_test_suite_helper:assert_received_messages([
  929. {on_process_unregistered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, {syn_remote_scope_node_down, scope_all, SlaveNode1}}
  930. ]),
  931. syn_test_suite_helper:assert_empty_queue(self()),
  932. %% ---> after a re-join
  933. %% re-join
  934. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  935. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  936. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  937. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  938. %% check callbacks called
  939. syn_test_suite_helper:assert_received_messages([
  940. {on_process_registered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, {syn_remote_scope_node_up, scope_all, SlaveNode1}}
  941. ]),
  942. syn_test_suite_helper:assert_empty_queue(self()),
  943. %% clean
  944. syn_test_suite_helper:kill_process(PidRemoteOn1),
  945. %% check callbacks called
  946. syn_test_suite_helper:assert_received_messages([
  947. {on_process_unregistered, LocalNode, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, killed},
  948. {on_process_unregistered, SlaveNode1, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, killed},
  949. {on_process_unregistered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, killed}
  950. ]),
  951. syn_test_suite_helper:assert_empty_queue(self()),
  952. %% ---> after a conflict resolution
  953. %% partial netsplit (1 cannot see 2)
  954. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  955. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  956. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  957. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  958. %% start conflict processes
  959. Pid2RemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  960. Pid2RemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  961. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict", Pid2RemoteOn1, {recipient, self(), <<"meta-1">>}]),
  962. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict", Pid2RemoteOn2, {recipient, self(), <<"meta-2">>}]),
  963. %% check callbacks called
  964. syn_test_suite_helper:assert_received_messages([
  965. {on_process_registered, LocalNode, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  966. {on_process_unregistered, LocalNode, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  967. {on_process_registered, LocalNode, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, normal},
  968. {on_process_registered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  969. {on_process_registered, SlaveNode2, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, normal}
  970. ]),
  971. syn_test_suite_helper:assert_empty_queue(self()),
  972. %% re-join
  973. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  974. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  975. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  976. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  977. %% check callbacks called
  978. syn_test_suite_helper:assert_received_messages([
  979. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, syn_conflict_resolution},
  980. {on_process_registered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, syn_conflict_resolution}
  981. ]),
  982. syn_test_suite_helper:assert_empty_queue(self()),
  983. %% kill
  984. syn_test_suite_helper:kill_process(Pid2RemoteOn1),
  985. syn_test_suite_helper:kill_process(Pid2RemoteOn2),
  986. %% check callbacks called
  987. syn_test_suite_helper:assert_received_messages([
  988. {on_process_unregistered, LocalNode, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, killed},
  989. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, killed},
  990. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, killed}
  991. ]),
  992. syn_test_suite_helper:assert_empty_queue(self()),
  993. %% ---> don't call on monitor rebuild
  994. %% crash the scope process on local
  995. syn_test_suite_helper:kill_process(syn_registry_scope_all),
  996. syn_test_suite_helper:wait_process_name_ready(syn_registry_scope_all),
  997. %% no messages
  998. syn_test_suite_helper:assert_wait(
  999. ok,
  1000. fun() -> syn_test_suite_helper:assert_empty_queue(self()) end
  1001. ),
  1002. %% ---> call if process died during the scope process crash
  1003. TransientPid = syn_test_suite_helper:start_process(),
  1004. syn:register(scope_all, "transient-pid", TransientPid, {recipient, self(), "transient-meta"}),
  1005. %% check callbacks called
  1006. syn_test_suite_helper:assert_received_messages([
  1007. {on_process_registered, LocalNode, scope_all, "transient-pid", TransientPid, "transient-meta", normal},
  1008. {on_process_registered, SlaveNode1, scope_all, "transient-pid", TransientPid, "transient-meta", normal},
  1009. {on_process_registered, SlaveNode2, scope_all, "transient-pid", TransientPid, "transient-meta", normal}
  1010. ]),
  1011. syn_test_suite_helper:assert_empty_queue(self()),
  1012. %% crash the scope process & transient process on local
  1013. syn_test_suite_helper:kill_process(syn_registry_scope_all),
  1014. syn_test_suite_helper:kill_process(TransientPid),
  1015. %% check callbacks called
  1016. syn_test_suite_helper:assert_received_messages([
  1017. {on_process_unregistered, LocalNode, scope_all, "transient-pid", TransientPid, "transient-meta", undefined},
  1018. {on_process_unregistered, SlaveNode1, scope_all, "transient-pid", TransientPid, "transient-meta", {syn_remote_scope_node_down, scope_all, LocalNode}},
  1019. {on_process_unregistered, SlaveNode2, scope_all, "transient-pid", TransientPid, "transient-meta", {syn_remote_scope_node_down, scope_all, LocalNode}}
  1020. ]),
  1021. syn_test_suite_helper:assert_empty_queue(self()).
  1022. three_nodes_custom_event_handler_conflict_resolution(Config) ->
  1023. %% get slaves
  1024. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  1025. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  1026. %% add custom handler for resolution
  1027. syn:set_event_handler(syn_test_event_handler_resolution),
  1028. rpc:call(SlaveNode1, syn, set_event_handler, [syn_test_event_handler_resolution]),
  1029. rpc:call(SlaveNode2, syn, set_event_handler, [syn_test_event_handler_resolution]),
  1030. %% start syn on nodes
  1031. ok = syn:start(),
  1032. ok = rpc:call(SlaveNode1, syn, start, []),
  1033. ok = rpc:call(SlaveNode2, syn, start, []),
  1034. %% add scopes
  1035. ok = syn:add_node_to_scopes([scope_all]),
  1036. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  1037. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  1038. %% current node
  1039. TestPid = self(),
  1040. LocalNode = node(),
  1041. %% partial netsplit (1 cannot see 2)
  1042. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1043. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1044. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1045. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1046. %% start conflict processes
  1047. PidOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  1048. PidOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  1049. %% --> conflict by netsplit
  1050. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom", PidOn1, {recipient, TestPid, keepthis}]),
  1051. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom", PidOn2, {recipient, TestPid, "meta-2"}]),
  1052. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, {recipient, TestPid, keepthis}]),
  1053. ok = rpc:call(SlaveNode2, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, {recipient, TestPid, "meta-2"}]),
  1054. %% check callbacks
  1055. syn_test_suite_helper:assert_received_messages([
  1056. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1057. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1058. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", normal},
  1059. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1060. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", normal},
  1061. {on_process_registered, SlaveNode1, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal},
  1062. {on_process_registered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, "meta-2", normal}
  1063. ]),
  1064. syn_test_suite_helper:assert_empty_queue(self()),
  1065. %% re-join
  1066. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1067. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1068. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1069. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1070. %% retrieve
  1071. syn_test_suite_helper:assert_wait(
  1072. {PidOn1, {recipient, TestPid, keepthis}},
  1073. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom") end
  1074. ),
  1075. syn_test_suite_helper:assert_wait(
  1076. {PidOn1, {recipient, TestPid, keepthis}},
  1077. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1078. ),
  1079. syn_test_suite_helper:assert_wait(
  1080. {PidOn1, {recipient, TestPid, keepthis}},
  1081. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1082. ),
  1083. 1 = syn:registry_count(scope_all),
  1084. 0 = syn:registry_count(scope_all, node()),
  1085. 1 = syn:registry_count(scope_all, SlaveNode1),
  1086. 0 = syn:registry_count(scope_all, SlaveNode2),
  1087. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1088. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1089. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1090. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1091. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1092. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1093. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1094. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1095. syn_test_suite_helper:assert_wait(
  1096. {PidOn1, {recipient, TestPid, keepthis}},
  1097. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1098. ),
  1099. syn_test_suite_helper:assert_wait(
  1100. {PidOn1, {recipient, TestPid, keepthis}},
  1101. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1102. ),
  1103. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  1104. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  1105. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  1106. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  1107. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  1108. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  1109. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  1110. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  1111. syn_test_suite_helper:assert_received_messages([
  1112. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1113. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, syn_conflict_resolution},
  1114. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1115. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, syn_conflict_resolution},
  1116. {on_process_unregistered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1117. {on_process_registered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, syn_conflict_resolution}
  1118. ]),
  1119. syn_test_suite_helper:assert_empty_queue(self()),
  1120. %% process alive (discarded process does not get killed with a custom handler)
  1121. syn_test_suite_helper:assert_wait(
  1122. true,
  1123. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1124. ),
  1125. syn_test_suite_helper:assert_wait(
  1126. true,
  1127. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1128. ),
  1129. %% clean up default scope
  1130. syn:unregister(scope_all, "proc-confict-by-netsplit-custom"),
  1131. ok = rpc:call(SlaveNode1, syn, unregister, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]),
  1132. %% retrieve
  1133. syn_test_suite_helper:assert_wait(
  1134. undefined,
  1135. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom") end
  1136. ),
  1137. syn_test_suite_helper:assert_wait(
  1138. undefined,
  1139. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1140. ),
  1141. syn_test_suite_helper:assert_wait(
  1142. undefined,
  1143. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1144. ),
  1145. syn_test_suite_helper:assert_wait(
  1146. undefined,
  1147. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1148. ),
  1149. syn_test_suite_helper:assert_wait(
  1150. undefined,
  1151. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1152. ),
  1153. %% check callbacks
  1154. syn_test_suite_helper:assert_received_messages([
  1155. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1156. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1157. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1158. {on_process_unregistered, SlaveNode1, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal},
  1159. {on_process_unregistered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal}
  1160. ]),
  1161. syn_test_suite_helper:assert_empty_queue(self()),
  1162. %% --> conflict by netsplit, which returns invalid pid
  1163. %% partial netsplit (1 cannot see 2)
  1164. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1165. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1166. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1167. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1168. %% register with meta with no 'keepthis' element
  1169. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, {recipient, TestPid, "meta-1"}]),
  1170. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, {recipient, TestPid, "meta-2"}]),
  1171. %% check callbacks
  1172. syn_test_suite_helper:assert_received_messages([
  1173. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1174. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1175. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", normal},
  1176. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1177. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", normal}
  1178. ]),
  1179. syn_test_suite_helper:assert_empty_queue(self()),
  1180. %% re-join
  1181. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1182. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1183. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1184. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1185. %% retrieve (names get freed)
  1186. syn_test_suite_helper:assert_wait(
  1187. undefined,
  1188. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom-other-pid") end
  1189. ),
  1190. syn_test_suite_helper:assert_wait(
  1191. undefined,
  1192. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-other-pid"]) end
  1193. ),
  1194. syn_test_suite_helper:assert_wait(
  1195. undefined,
  1196. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-other-pid"]) end
  1197. ),
  1198. 0 = syn:registry_count(scope_all),
  1199. 0 = syn:registry_count(scope_all, node()),
  1200. 0 = syn:registry_count(scope_all, SlaveNode1),
  1201. 0 = syn:registry_count(scope_all, SlaveNode2),
  1202. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1203. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1204. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1205. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1206. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1207. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1208. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1209. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1210. %% check callbacks
  1211. syn_test_suite_helper:assert_received_messages([
  1212. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", syn_conflict_resolution},
  1213. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", syn_conflict_resolution},
  1214. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", syn_conflict_resolution}
  1215. ]),
  1216. syn_test_suite_helper:assert_empty_queue(self()),
  1217. %% process alive (discarded process does not get killed with a custom handler)
  1218. syn_test_suite_helper:assert_wait(
  1219. true,
  1220. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1221. ),
  1222. syn_test_suite_helper:assert_wait(
  1223. true,
  1224. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1225. ),
  1226. %% --> conflict by netsplit, which crashes
  1227. %% partial netsplit (1 cannot see 2)
  1228. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1229. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1230. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1231. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1232. %% register with meta with no 'crash' element
  1233. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, {recipient, TestPid, crash}]),
  1234. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, {recipient, TestPid, crash}]),
  1235. %% check callbacks
  1236. syn_test_suite_helper:assert_received_messages([
  1237. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1238. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1239. {on_process_registered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, normal},
  1240. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1241. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, normal}
  1242. ]),
  1243. syn_test_suite_helper:assert_empty_queue(self()),
  1244. %% re-join
  1245. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1246. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1247. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1248. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1249. %% retrieve (names get freed)
  1250. syn_test_suite_helper:assert_wait(
  1251. undefined,
  1252. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom-crash") end
  1253. ),
  1254. syn_test_suite_helper:assert_wait(
  1255. undefined,
  1256. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-crash"]) end
  1257. ),
  1258. syn_test_suite_helper:assert_wait(
  1259. undefined,
  1260. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-crash"]) end
  1261. ),
  1262. 0 = syn:registry_count(scope_all),
  1263. 0 = syn:registry_count(scope_all, node()),
  1264. 0 = syn:registry_count(scope_all, SlaveNode1),
  1265. 0 = syn:registry_count(scope_all, SlaveNode2),
  1266. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1267. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1268. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1269. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1270. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1271. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1272. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1273. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1274. %% check callbacks
  1275. syn_test_suite_helper:assert_received_messages([
  1276. {on_process_unregistered, LocalNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, syn_conflict_resolution},
  1277. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, syn_conflict_resolution},
  1278. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, syn_conflict_resolution}
  1279. ]),
  1280. syn_test_suite_helper:assert_empty_queue(self()),
  1281. %% process alive (discarded process does not get killed with a custom handler)
  1282. syn_test_suite_helper:assert_wait(
  1283. true,
  1284. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1285. ),
  1286. syn_test_suite_helper:assert_wait(
  1287. true,
  1288. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1289. ).
  1290. %% ===================================================================
  1291. %% Internal
  1292. %% ===================================================================
  1293. add_to_local_table(Scope, Name, Pid, Meta, Time, MRef) ->
  1294. TableByName = syn_backbone:get_table_name(syn_registry_by_name, Scope),
  1295. TableByPid = syn_backbone:get_table_name(syn_registry_by_pid, Scope),
  1296. syn_registry:add_to_local_table(Name, Pid, Meta, Time, MRef, TableByName, TableByPid).
  1297. remove_from_local_table(Scope, Name, Pid) ->
  1298. TableByName = syn_backbone:get_table_name(syn_registry_by_name, Scope),
  1299. TableByPid = syn_backbone:get_table_name(syn_registry_by_pid, Scope),
  1300. syn_registry:remove_from_local_table(Name, Pid, TableByName, TableByPid).