syn_registry_SUITE.erl 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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. %% crash scope process to ensure that monitors get recreated
  397. syn_test_suite_helper:kill_process(syn_registry_scope_ab),
  398. syn_test_suite_helper:wait_process_name_ready(syn_registry_scope_ab),
  399. %% kill process
  400. syn_test_suite_helper:kill_process(Pid),
  401. syn_test_suite_helper:kill_process(PidWithMeta),
  402. %% unregister processes
  403. {error, undefined} = catch syn:unregister(scope_ab, <<"my proc with meta">>),
  404. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:unregister(scope_bc, <<"my proc with meta">>),
  405. ok = rpc:call(SlaveNode1, syn, unregister, [scope_bc, {remote_scoped_bc}]),
  406. %% retrieve
  407. syn_test_suite_helper:assert_wait(
  408. undefined,
  409. fun() -> syn:lookup(scope_ab, "scope_a") end
  410. ),
  411. syn_test_suite_helper:assert_wait(
  412. undefined,
  413. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a"]) end
  414. ),
  415. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a"]),
  416. syn_test_suite_helper:assert_wait(
  417. undefined,
  418. fun() -> syn:lookup(scope_ab, "scope_a_alias") end
  419. ),
  420. syn_test_suite_helper:assert_wait(
  421. undefined,
  422. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, "scope_a_alias"]) end
  423. ),
  424. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, lookup, [scope_ab, "scope_a_alias"]),
  425. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, {remote_scoped_bc}),
  426. syn_test_suite_helper:assert_wait(
  427. undefined,
  428. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, {remote_scoped_bc}]) end
  429. ),
  430. syn_test_suite_helper:assert_wait(
  431. undefined,
  432. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, {remote_scoped_bc}]) end
  433. ),
  434. 0 = syn:registry_count(scope_ab),
  435. 0 = syn:registry_count(scope_ab, node()),
  436. 0 = syn:registry_count(scope_ab, SlaveNode1),
  437. 0 = syn:registry_count(scope_ab, SlaveNode2),
  438. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  439. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, node()),
  440. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode1),
  441. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode2),
  442. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab]),
  443. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, node()]),
  444. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode1]),
  445. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_ab, SlaveNode2]),
  446. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  447. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  448. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  449. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  450. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab]),
  451. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, node()]),
  452. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode1]),
  453. {badrpc, {'EXIT', {{invalid_scope, scope_ab}, _}}} = catch rpc:call(SlaveNode2, syn, registry_count, [scope_ab, SlaveNode2]),
  454. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  455. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  456. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  457. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  458. %% errors
  459. {error, undefined} = syn:unregister(scope_ab, {invalid_name}),
  460. %% (simulate race condition)
  461. Pid1 = syn_test_suite_helper:start_process(),
  462. Pid2 = syn_test_suite_helper:start_process(),
  463. ok = syn:register(scope_ab, <<"my proc">>, Pid1),
  464. syn_test_suite_helper:assert_wait(
  465. {Pid1, undefined},
  466. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_ab, <<"my proc">>]) end
  467. ),
  468. remove_from_local_table(scope_ab, <<"my proc">>, Pid1),
  469. add_to_local_table(scope_ab, <<"my proc">>, Pid2, undefined, 0, undefined),
  470. {error, race_condition} = rpc:call(SlaveNode1, syn, unregister, [scope_ab, <<"my proc">>]).
  471. three_nodes_register_filter_unknown_node(Config) ->
  472. %% get slaves
  473. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  474. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  475. %% start syn on 1 and 2
  476. ok = rpc:call(SlaveNode1, syn, start, []),
  477. ok = rpc:call(SlaveNode2, syn, start, []),
  478. %% add scopes
  479. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_bc]]),
  480. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_bc]]),
  481. %% send sync message from out of scope node
  482. InvalidPid = syn_test_suite_helper:start_process(),
  483. {syn_registry_scope_bc, SlaveNode1} ! {'3.0', sync_register, <<"proc-name">>, InvalidPid, undefined, os:system_time(millisecond), normal},
  484. %% check
  485. undefined = rpc:call(SlaveNode1, syn, lookup, [scope_bc, <<"proc-name">>]).
  486. three_nodes_cluster_changes(Config) ->
  487. %% get slaves
  488. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  489. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  490. %% disconnect 1 from 2
  491. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  492. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  493. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  494. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  495. %% start syn on 1 and 2, nodes don't know of each other
  496. ok = rpc:call(SlaveNode1, syn, start, []),
  497. ok = rpc:call(SlaveNode2, syn, start, []),
  498. %% add scopes
  499. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  500. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  501. %% start processes
  502. PidRemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  503. PidRemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  504. %% register
  505. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-1", PidRemoteOn1, "meta-1"]),
  506. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-2", PidRemoteOn2, "meta-2"]),
  507. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "BC-proc-1", PidRemoteOn1, "meta-1"]),
  508. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "BC-proc-1 alias", PidRemoteOn1, "meta-1 alias"]),
  509. %% form full cluster
  510. ok = syn:start(),
  511. ok = syn:add_node_to_scopes([scope_all]),
  512. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  513. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  514. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  515. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  516. %% retrieve
  517. syn_test_suite_helper:assert_wait(
  518. {PidRemoteOn1, "meta-1"},
  519. fun() -> syn:lookup(scope_all, "proc-1") end
  520. ),
  521. syn_test_suite_helper:assert_wait(
  522. {PidRemoteOn1, "meta-1"},
  523. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-1"]) end
  524. ),
  525. syn_test_suite_helper:assert_wait(
  526. {PidRemoteOn1, "meta-1"},
  527. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-1"]) end
  528. ),
  529. syn_test_suite_helper:assert_wait(
  530. {PidRemoteOn2, "meta-2"},
  531. fun() -> syn:lookup(scope_all, "proc-2") end
  532. ),
  533. syn_test_suite_helper:assert_wait(
  534. {PidRemoteOn2, "meta-2"},
  535. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-2"]) end
  536. ),
  537. syn_test_suite_helper:assert_wait(
  538. {PidRemoteOn2, "meta-2"},
  539. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-2"]) end
  540. ),
  541. 2 = syn:registry_count(scope_all),
  542. 0 = syn:registry_count(scope_all, node()),
  543. 1 = syn:registry_count(scope_all, SlaveNode1),
  544. 1 = syn:registry_count(scope_all, SlaveNode2),
  545. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  546. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  547. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  548. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  549. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  550. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  551. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  552. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  553. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1"),
  554. syn_test_suite_helper:assert_wait(
  555. {PidRemoteOn1, "meta-1"},
  556. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1"]) end
  557. ),
  558. syn_test_suite_helper:assert_wait(
  559. {PidRemoteOn1, "meta-1"},
  560. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1"]) end
  561. ),
  562. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1 alias"),
  563. syn_test_suite_helper:assert_wait(
  564. {PidRemoteOn1, "meta-1 alias"},
  565. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  566. ),
  567. syn_test_suite_helper:assert_wait(
  568. {PidRemoteOn1, "meta-1 alias"},
  569. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  570. ),
  571. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  572. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, node()),
  573. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode1),
  574. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc, SlaveNode2),
  575. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  576. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  577. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  578. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  579. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  580. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  581. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  582. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  583. %% partial netsplit (1 cannot see 2)
  584. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  585. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  586. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  587. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  588. %% retrieve
  589. syn_test_suite_helper:assert_wait(
  590. {PidRemoteOn1, "meta-1"},
  591. fun() -> syn:lookup(scope_all, "proc-1") end
  592. ),
  593. syn_test_suite_helper:assert_wait(
  594. {PidRemoteOn1, "meta-1"},
  595. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-1"]) end
  596. ),
  597. syn_test_suite_helper:assert_wait(
  598. undefined,
  599. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-1"]) end
  600. ),
  601. syn_test_suite_helper:assert_wait(
  602. {PidRemoteOn2, "meta-2"},
  603. fun() -> syn:lookup(scope_all, "proc-2") end
  604. ),
  605. syn_test_suite_helper:assert_wait(
  606. undefined,
  607. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-2"]) end
  608. ),
  609. syn_test_suite_helper:assert_wait(
  610. {PidRemoteOn2, "meta-2"},
  611. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-2"]) end
  612. ),
  613. 2 = syn:registry_count(scope_all),
  614. 0 = syn:registry_count(scope_all, node()),
  615. 1 = syn:registry_count(scope_all, SlaveNode1),
  616. 1 = syn:registry_count(scope_all, SlaveNode2),
  617. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  618. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  619. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  620. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  621. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  622. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  623. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  624. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  625. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1"),
  626. syn_test_suite_helper:assert_wait(
  627. {PidRemoteOn1, "meta-1"},
  628. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1"]) end
  629. ),
  630. syn_test_suite_helper:assert_wait(
  631. undefined,
  632. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1"]) end
  633. ),
  634. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1 alias"),
  635. syn_test_suite_helper:assert_wait(
  636. {PidRemoteOn1, "meta-1 alias"},
  637. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  638. ),
  639. syn_test_suite_helper:assert_wait(
  640. undefined,
  641. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  642. ),
  643. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  644. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  645. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  646. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  647. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  648. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  649. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  650. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  651. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  652. %% re-join
  653. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  654. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  655. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  656. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  657. %% retrieve
  658. syn_test_suite_helper:assert_wait(
  659. {PidRemoteOn1, "meta-1"},
  660. fun() -> syn:lookup(scope_all, "proc-1") end
  661. ),
  662. syn_test_suite_helper:assert_wait(
  663. {PidRemoteOn1, "meta-1"},
  664. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-1"]) end
  665. ),
  666. syn_test_suite_helper:assert_wait(
  667. {PidRemoteOn1, "meta-1"},
  668. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-1"]) end
  669. ),
  670. syn_test_suite_helper:assert_wait(
  671. {PidRemoteOn2, "meta-2"},
  672. fun() -> syn:lookup(scope_all, "proc-2") end
  673. ),
  674. syn_test_suite_helper:assert_wait(
  675. {PidRemoteOn2, "meta-2"},
  676. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-2"]) end
  677. ),
  678. syn_test_suite_helper:assert_wait(
  679. {PidRemoteOn2, "meta-2"},
  680. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-2"]) end
  681. ),
  682. 2 = syn:registry_count(scope_all),
  683. 0 = syn:registry_count(scope_all, node()),
  684. 1 = syn:registry_count(scope_all, SlaveNode1),
  685. 1 = syn:registry_count(scope_all, SlaveNode2),
  686. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  687. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  688. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  689. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  690. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  691. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  692. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  693. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  694. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1"),
  695. syn_test_suite_helper:assert_wait(
  696. {PidRemoteOn1, "meta-1"},
  697. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1"]) end
  698. ),
  699. syn_test_suite_helper:assert_wait(
  700. {PidRemoteOn1, "meta-1"},
  701. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1"]) end
  702. ),
  703. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:lookup(scope_bc, "BC-proc-1 alias"),
  704. syn_test_suite_helper:assert_wait(
  705. {PidRemoteOn1, "meta-1 alias"},
  706. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  707. ),
  708. syn_test_suite_helper:assert_wait(
  709. {PidRemoteOn1, "meta-1 alias"},
  710. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "BC-proc-1 alias"]) end
  711. ),
  712. {'EXIT', {{invalid_scope, scope_bc}, _}} = catch syn:registry_count(scope_bc),
  713. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  714. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  715. 2 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  716. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  717. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  718. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  719. 2 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  720. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]).
  721. three_nodes_cluster_conflicts(Config) ->
  722. %% get slaves
  723. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  724. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  725. %% start syn on nodes
  726. ok = syn:start(),
  727. ok = rpc:call(SlaveNode1, syn, start, []),
  728. ok = rpc:call(SlaveNode2, syn, start, []),
  729. %% add scopes
  730. ok = syn:add_node_to_scopes([scope_all]),
  731. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  732. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  733. %% partial netsplit (1 cannot see 2)
  734. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  735. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  736. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  737. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  738. %% start conflict processes
  739. Pid2RemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  740. Pid2RemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  741. %% --> conflict by netsplit
  742. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit", Pid2RemoteOn1, "meta-1"]),
  743. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit", Pid2RemoteOn2, "meta-2"]),
  744. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped", Pid2RemoteOn1, "meta-1"]),
  745. ok = rpc:call(SlaveNode2, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped", Pid2RemoteOn2, "meta-2"]),
  746. %% re-join
  747. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  748. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  749. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  750. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  751. %% retrieve
  752. syn_test_suite_helper:assert_wait(
  753. {Pid2RemoteOn2, "meta-2"},
  754. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit") end
  755. ),
  756. syn_test_suite_helper:assert_wait(
  757. {Pid2RemoteOn2, "meta-2"},
  758. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit"]) end
  759. ),
  760. syn_test_suite_helper:assert_wait(
  761. {Pid2RemoteOn2, "meta-2"},
  762. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit"]) end
  763. ),
  764. 1 = syn:registry_count(scope_all),
  765. 0 = syn:registry_count(scope_all, node()),
  766. 0 = syn:registry_count(scope_all, SlaveNode1),
  767. 1 = syn:registry_count(scope_all, SlaveNode2),
  768. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  769. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  770. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  771. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  772. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  773. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  774. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  775. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  776. syn_test_suite_helper:assert_wait(
  777. {Pid2RemoteOn2, "meta-2"},
  778. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped"]) end
  779. ),
  780. syn_test_suite_helper:assert_wait(
  781. {Pid2RemoteOn2, "meta-2"},
  782. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped"]) end
  783. ),
  784. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  785. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  786. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  787. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  788. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  789. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  790. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  791. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  792. %% process alive
  793. syn_test_suite_helper:assert_wait(
  794. false,
  795. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [Pid2RemoteOn1]) end
  796. ),
  797. syn_test_suite_helper:assert_wait(
  798. true,
  799. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [Pid2RemoteOn2]) end
  800. ),
  801. %% --> conflict by race condition
  802. PidOnMaster = syn_test_suite_helper:start_process(),
  803. PidOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  804. rpc:call(SlaveNode1, syn_registry, add_to_local_table,
  805. [default, <<"my proc">>, PidOn1, "meta-2", erlang:system_time(), undefined]
  806. ),
  807. ok = syn:register(scope_all, <<"my proc">>, PidOnMaster, "meta-1"),
  808. %% retrieve
  809. syn_test_suite_helper:assert_wait(
  810. {PidOnMaster, "meta-1"},
  811. fun() -> syn:lookup(scope_all, <<"my proc">>) end
  812. ),
  813. syn_test_suite_helper:assert_wait(
  814. {PidOnMaster, "meta-1"},
  815. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, <<"my proc">>]) end
  816. ),
  817. syn_test_suite_helper:assert_wait(
  818. {PidOnMaster, "meta-1"},
  819. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, <<"my proc">>]) end
  820. ).
  821. %% NB: we can't check for process alive here because we injected the conflicting process in the DB
  822. %% -> it's not actually monitored
  823. three_nodes_custom_event_handler_reg_unreg(Config) ->
  824. %% get slaves
  825. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  826. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  827. %% add custom handler for callbacks
  828. syn:set_event_handler(syn_test_event_handler_callbacks),
  829. rpc:call(SlaveNode1, syn, set_event_handler, [syn_test_event_handler_callbacks]),
  830. rpc:call(SlaveNode2, syn, set_event_handler, [syn_test_event_handler_callbacks]),
  831. %% start syn on nodes
  832. ok = syn:start(),
  833. ok = rpc:call(SlaveNode1, syn, start, []),
  834. ok = rpc:call(SlaveNode2, syn, start, []),
  835. %% add scopes
  836. ok = syn:add_node_to_scopes([scope_all]),
  837. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all]]),
  838. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all]]),
  839. %% init
  840. CurrentNode = node(),
  841. %% start process
  842. Pid = syn_test_suite_helper:start_process(),
  843. Pid2 = syn_test_suite_helper:start_process(),
  844. %% ---> on registration
  845. ok = syn:register(scope_all, "proc-handler", Pid, {recipient, self(), <<"meta">>}),
  846. %% check callbacks called
  847. syn_test_suite_helper:assert_received_messages([
  848. {on_process_registered, CurrentNode, scope_all, "proc-handler", Pid, <<"meta">>, normal},
  849. {on_process_registered, SlaveNode1, scope_all, "proc-handler", Pid, <<"meta">>, normal},
  850. {on_process_registered, SlaveNode2, scope_all, "proc-handler", Pid, <<"meta">>, normal}
  851. ]),
  852. syn_test_suite_helper:assert_empty_queue(self()),
  853. %% registration from another node
  854. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-handler-2", Pid2, {recipient, self(), <<"meta-for-2">>}]),
  855. %% check callbacks called
  856. syn_test_suite_helper:assert_received_messages([
  857. {on_process_registered, CurrentNode, scope_all, "proc-handler-2", Pid2, <<"meta-for-2">>, normal},
  858. {on_process_registered, SlaveNode1, scope_all, "proc-handler-2", Pid2, <<"meta-for-2">>, normal},
  859. {on_process_registered, SlaveNode2, scope_all, "proc-handler-2", Pid2, <<"meta-for-2">>, normal}
  860. ]),
  861. syn_test_suite_helper:assert_empty_queue(self()),
  862. %% ---> on meta update
  863. ok = syn:register(scope_all, "proc-handler", Pid, {recipient, self(), <<"new-meta">>}),
  864. %% check callbacks called
  865. syn_test_suite_helper:assert_received_messages([
  866. {on_registry_process_updated, CurrentNode, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  867. {on_registry_process_updated, SlaveNode1, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  868. {on_registry_process_updated, SlaveNode2, scope_all, "proc-handler", Pid, <<"new-meta">>, normal}
  869. ]),
  870. syn_test_suite_helper:assert_empty_queue(self()),
  871. %% meta update from another node
  872. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-handler-2", Pid2, {recipient, self(), <<"meta-for-2-update">>}]),
  873. %% check callbacks called
  874. syn_test_suite_helper:assert_received_messages([
  875. {on_registry_process_updated, CurrentNode, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  876. {on_registry_process_updated, SlaveNode1, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  877. {on_registry_process_updated, SlaveNode2, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal}
  878. ]),
  879. syn_test_suite_helper:assert_empty_queue(self()),
  880. %% ---> on unregister
  881. ok = syn:unregister(scope_all, "proc-handler"),
  882. %% check callbacks called
  883. syn_test_suite_helper:assert_received_messages([
  884. {on_process_unregistered, CurrentNode, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  885. {on_process_unregistered, SlaveNode1, scope_all, "proc-handler", Pid, <<"new-meta">>, normal},
  886. {on_process_unregistered, SlaveNode2, scope_all, "proc-handler", Pid, <<"new-meta">>, normal}
  887. ]),
  888. syn_test_suite_helper:assert_empty_queue(self()),
  889. %% unregister from another node
  890. ok = rpc:call(SlaveNode1, syn, unregister, [scope_all, "proc-handler-2"]),
  891. %% check callbacks called
  892. syn_test_suite_helper:assert_received_messages([
  893. {on_process_unregistered, CurrentNode, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  894. {on_process_unregistered, SlaveNode1, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal},
  895. {on_process_unregistered, SlaveNode2, scope_all, "proc-handler-2", Pid2, <<"meta-for-2-update">>, normal}
  896. ]),
  897. syn_test_suite_helper:assert_empty_queue(self()),
  898. %% clean & check
  899. syn_test_suite_helper:kill_process(Pid),
  900. syn_test_suite_helper:assert_empty_queue(self()),
  901. %% ---> after a netsplit
  902. PidRemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  903. syn:register(scope_all, remote_on_1, PidRemoteOn1, {recipient, self(), <<"netsplit">>}),
  904. %% check callbacks called
  905. syn_test_suite_helper:assert_received_messages([
  906. {on_process_registered, CurrentNode, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, normal},
  907. {on_process_registered, SlaveNode1, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, normal},
  908. {on_process_registered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, normal}
  909. ]),
  910. syn_test_suite_helper:assert_empty_queue(self()),
  911. %% partial netsplit (1 cannot see 2)
  912. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  913. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  914. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  915. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  916. %% check callbacks called
  917. syn_test_suite_helper:assert_received_messages([
  918. {on_process_unregistered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, {syn_remote_scope_node_down, scope_all, SlaveNode1}}
  919. ]),
  920. syn_test_suite_helper:assert_empty_queue(self()),
  921. %% ---> after a re-join
  922. %% re-join
  923. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  924. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  925. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  926. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  927. %% check callbacks called
  928. syn_test_suite_helper:assert_received_messages([
  929. {on_process_registered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, {syn_remote_scope_node_up, scope_all, SlaveNode1}}
  930. ]),
  931. syn_test_suite_helper:assert_empty_queue(self()),
  932. %% clean
  933. syn_test_suite_helper:kill_process(PidRemoteOn1),
  934. %% check callbacks called
  935. syn_test_suite_helper:assert_received_messages([
  936. {on_process_unregistered, CurrentNode, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, killed},
  937. {on_process_unregistered, SlaveNode1, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, killed},
  938. {on_process_unregistered, SlaveNode2, scope_all, remote_on_1, PidRemoteOn1, <<"netsplit">>, killed}
  939. ]),
  940. syn_test_suite_helper:assert_empty_queue(self()),
  941. %% ---> after a conflict resolution
  942. %% partial netsplit (1 cannot see 2)
  943. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  944. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  945. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  946. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  947. %% start conflict processes
  948. Pid2RemoteOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  949. Pid2RemoteOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  950. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict", Pid2RemoteOn1, {recipient, self(), <<"meta-1">>}]),
  951. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict", Pid2RemoteOn2, {recipient, self(), <<"meta-2">>}]),
  952. %% check callbacks called
  953. syn_test_suite_helper:assert_received_messages([
  954. {on_process_registered, CurrentNode, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  955. {on_process_unregistered, CurrentNode, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  956. {on_process_registered, CurrentNode, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, normal},
  957. {on_process_registered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  958. {on_process_registered, SlaveNode2, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, normal}
  959. ]),
  960. syn_test_suite_helper:assert_empty_queue(self()),
  961. %% re-join
  962. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  963. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  964. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  965. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  966. %% check callbacks called
  967. syn_test_suite_helper:assert_received_messages([
  968. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, syn_conflict_resolution},
  969. {on_process_registered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, syn_conflict_resolution}
  970. ]),
  971. syn_test_suite_helper:assert_empty_queue(self()),
  972. %% kill
  973. syn_test_suite_helper:kill_process(Pid2RemoteOn1),
  974. syn_test_suite_helper:kill_process(Pid2RemoteOn2),
  975. %% check callbacks called
  976. syn_test_suite_helper:assert_received_messages([
  977. {on_process_unregistered, CurrentNode, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, killed},
  978. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, killed},
  979. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict", Pid2RemoteOn2, <<"meta-2">>, killed}
  980. ]),
  981. syn_test_suite_helper:assert_empty_queue(self()),
  982. %% ---> don't call on monitor rebuild
  983. %% crash the scope process on local
  984. syn_test_suite_helper:kill_process(syn_registry_scope_all),
  985. %% no messages
  986. syn_test_suite_helper:assert_wait(
  987. ok,
  988. fun() -> syn_test_suite_helper:assert_empty_queue(self()) end
  989. ).
  990. three_nodes_custom_event_handler_conflict_resolution(Config) ->
  991. %% get slaves
  992. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  993. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  994. %% add custom handler for resolution
  995. syn:set_event_handler(syn_test_event_handler_resolution),
  996. rpc:call(SlaveNode1, syn, set_event_handler, [syn_test_event_handler_resolution]),
  997. rpc:call(SlaveNode2, syn, set_event_handler, [syn_test_event_handler_resolution]),
  998. %% start syn on nodes
  999. ok = syn:start(),
  1000. ok = rpc:call(SlaveNode1, syn, start, []),
  1001. ok = rpc:call(SlaveNode2, syn, start, []),
  1002. %% add scopes
  1003. ok = syn:add_node_to_scopes([scope_all]),
  1004. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  1005. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  1006. %% current node
  1007. TestPid = self(),
  1008. CurrentNode = node(),
  1009. %% partial netsplit (1 cannot see 2)
  1010. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1011. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1012. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1013. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1014. %% start conflict processes
  1015. PidOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  1016. PidOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  1017. %% --> conflict by netsplit
  1018. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom", PidOn1, {recipient, TestPid, keepthis}]),
  1019. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom", PidOn2, {recipient, TestPid, "meta-2"}]),
  1020. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, {recipient, TestPid, keepthis}]),
  1021. ok = rpc:call(SlaveNode2, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, {recipient, TestPid, "meta-2"}]),
  1022. %% check callbacks
  1023. syn_test_suite_helper:assert_received_messages([
  1024. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1025. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1026. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", normal},
  1027. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1028. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", normal},
  1029. {on_process_registered, SlaveNode1, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal},
  1030. {on_process_registered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, "meta-2", normal}
  1031. ]),
  1032. syn_test_suite_helper:assert_empty_queue(self()),
  1033. %% re-join
  1034. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1035. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1036. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1037. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1038. %% retrieve
  1039. syn_test_suite_helper:assert_wait(
  1040. {PidOn1, {recipient, TestPid, keepthis}},
  1041. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom") end
  1042. ),
  1043. syn_test_suite_helper:assert_wait(
  1044. {PidOn1, {recipient, TestPid, keepthis}},
  1045. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1046. ),
  1047. syn_test_suite_helper:assert_wait(
  1048. {PidOn1, {recipient, TestPid, keepthis}},
  1049. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1050. ),
  1051. 1 = syn:registry_count(scope_all),
  1052. 0 = syn:registry_count(scope_all, node()),
  1053. 1 = syn:registry_count(scope_all, SlaveNode1),
  1054. 0 = syn:registry_count(scope_all, SlaveNode2),
  1055. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1056. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1057. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1058. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1059. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1060. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1061. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1062. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1063. syn_test_suite_helper:assert_wait(
  1064. {PidOn1, {recipient, TestPid, keepthis}},
  1065. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1066. ),
  1067. syn_test_suite_helper:assert_wait(
  1068. {PidOn1, {recipient, TestPid, keepthis}},
  1069. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1070. ),
  1071. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  1072. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  1073. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  1074. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  1075. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  1076. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  1077. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  1078. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  1079. syn_test_suite_helper:assert_received_messages([
  1080. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1081. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, syn_conflict_resolution},
  1082. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1083. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, syn_conflict_resolution},
  1084. {on_process_unregistered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1085. {on_process_registered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, syn_conflict_resolution}
  1086. ]),
  1087. syn_test_suite_helper:assert_empty_queue(self()),
  1088. %% process alive (discarded process does not get killed with a custom handler)
  1089. syn_test_suite_helper:assert_wait(
  1090. true,
  1091. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1092. ),
  1093. syn_test_suite_helper:assert_wait(
  1094. true,
  1095. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1096. ),
  1097. %% clean up default scope
  1098. syn:unregister(scope_all, "proc-confict-by-netsplit-custom"),
  1099. ok = rpc:call(SlaveNode1, syn, unregister, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]),
  1100. %% retrieve
  1101. syn_test_suite_helper:assert_wait(
  1102. undefined,
  1103. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom") end
  1104. ),
  1105. syn_test_suite_helper:assert_wait(
  1106. undefined,
  1107. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1108. ),
  1109. syn_test_suite_helper:assert_wait(
  1110. undefined,
  1111. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1112. ),
  1113. syn_test_suite_helper:assert_wait(
  1114. undefined,
  1115. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1116. ),
  1117. syn_test_suite_helper:assert_wait(
  1118. undefined,
  1119. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1120. ),
  1121. %% check callbacks
  1122. syn_test_suite_helper:assert_received_messages([
  1123. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1124. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1125. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1126. {on_process_unregistered, SlaveNode1, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal},
  1127. {on_process_unregistered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal}
  1128. ]),
  1129. syn_test_suite_helper:assert_empty_queue(self()),
  1130. %% --> conflict by netsplit, which returns invalid pid
  1131. %% partial netsplit (1 cannot see 2)
  1132. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1133. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1134. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1135. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1136. %% register with meta with no 'keepthis' element
  1137. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, {recipient, TestPid, "meta-1"}]),
  1138. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, {recipient, TestPid, "meta-2"}]),
  1139. %% check callbacks
  1140. syn_test_suite_helper:assert_received_messages([
  1141. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1142. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1143. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", normal},
  1144. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1145. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", normal}
  1146. ]),
  1147. syn_test_suite_helper:assert_empty_queue(self()),
  1148. %% re-join
  1149. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1150. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1151. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1152. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1153. %% retrieve (names get freed)
  1154. syn_test_suite_helper:assert_wait(
  1155. undefined,
  1156. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom-other-pid") end
  1157. ),
  1158. syn_test_suite_helper:assert_wait(
  1159. undefined,
  1160. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-other-pid"]) end
  1161. ),
  1162. syn_test_suite_helper:assert_wait(
  1163. undefined,
  1164. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-other-pid"]) end
  1165. ),
  1166. 0 = syn:registry_count(scope_all),
  1167. 0 = syn:registry_count(scope_all, node()),
  1168. 0 = syn:registry_count(scope_all, SlaveNode1),
  1169. 0 = syn:registry_count(scope_all, SlaveNode2),
  1170. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1171. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1172. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1173. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1174. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1175. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1176. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1177. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1178. %% check callbacks
  1179. syn_test_suite_helper:assert_received_messages([
  1180. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", syn_conflict_resolution},
  1181. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", syn_conflict_resolution},
  1182. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", syn_conflict_resolution}
  1183. ]),
  1184. syn_test_suite_helper:assert_empty_queue(self()),
  1185. %% process alive (discarded process does not get killed with a custom handler)
  1186. syn_test_suite_helper:assert_wait(
  1187. true,
  1188. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1189. ),
  1190. syn_test_suite_helper:assert_wait(
  1191. true,
  1192. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1193. ),
  1194. %% --> conflict by netsplit, which crashes
  1195. %% partial netsplit (1 cannot see 2)
  1196. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1197. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1198. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1199. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1200. %% register with meta with no 'crash' element
  1201. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, {recipient, TestPid, crash}]),
  1202. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, {recipient, TestPid, crash}]),
  1203. %% check callbacks
  1204. syn_test_suite_helper:assert_received_messages([
  1205. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1206. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1207. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, normal},
  1208. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1209. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, normal}
  1210. ]),
  1211. syn_test_suite_helper:assert_empty_queue(self()),
  1212. %% re-join
  1213. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1214. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1215. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1216. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1217. %% retrieve (names get freed)
  1218. syn_test_suite_helper:assert_wait(
  1219. undefined,
  1220. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom-crash") end
  1221. ),
  1222. syn_test_suite_helper:assert_wait(
  1223. undefined,
  1224. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-crash"]) end
  1225. ),
  1226. syn_test_suite_helper:assert_wait(
  1227. undefined,
  1228. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-crash"]) end
  1229. ),
  1230. 0 = syn:registry_count(scope_all),
  1231. 0 = syn:registry_count(scope_all, node()),
  1232. 0 = syn:registry_count(scope_all, SlaveNode1),
  1233. 0 = syn:registry_count(scope_all, SlaveNode2),
  1234. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1235. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1236. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1237. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1238. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1239. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1240. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1241. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1242. %% check callbacks
  1243. syn_test_suite_helper:assert_received_messages([
  1244. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, syn_conflict_resolution},
  1245. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, syn_conflict_resolution},
  1246. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, syn_conflict_resolution}
  1247. ]),
  1248. syn_test_suite_helper:assert_empty_queue(self()),
  1249. %% process alive (discarded process does not get killed with a custom handler)
  1250. syn_test_suite_helper:assert_wait(
  1251. true,
  1252. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1253. ),
  1254. syn_test_suite_helper:assert_wait(
  1255. true,
  1256. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1257. ).
  1258. %% ===================================================================
  1259. %% Internal
  1260. %% ===================================================================
  1261. add_to_local_table(Scope, Name, Pid, Meta, Time, MRef) ->
  1262. TableByName = syn_backbone:get_table_name(syn_registry_by_name, Scope),
  1263. TableByPid = syn_backbone:get_table_name(syn_registry_by_pid, Scope),
  1264. syn_registry:add_to_local_table(Name, Pid, Meta, Time, MRef, TableByName, TableByPid).
  1265. remove_from_local_table(Scope, Name, Pid) ->
  1266. TableByName = syn_backbone:get_table_name(syn_registry_by_name, Scope),
  1267. TableByPid = syn_backbone:get_table_name(syn_registry_by_pid, Scope),
  1268. syn_registry:remove_from_local_table(Name, Pid, TableByName, TableByPid).