syn_registry_SUITE.erl 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  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. CurrentNode = 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, 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, CurrentNode, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  966. {on_process_unregistered, CurrentNode, scope_all, "proc-confict", Pid2RemoteOn1, <<"meta-1">>, normal},
  967. {on_process_registered, CurrentNode, 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, CurrentNode, 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. %% no messages
  997. syn_test_suite_helper:assert_wait(
  998. ok,
  999. fun() -> syn_test_suite_helper:assert_empty_queue(self()) end
  1000. ).
  1001. three_nodes_custom_event_handler_conflict_resolution(Config) ->
  1002. %% get slaves
  1003. SlaveNode1 = proplists:get_value(slave_node_1, Config),
  1004. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  1005. %% add custom handler for resolution
  1006. syn:set_event_handler(syn_test_event_handler_resolution),
  1007. rpc:call(SlaveNode1, syn, set_event_handler, [syn_test_event_handler_resolution]),
  1008. rpc:call(SlaveNode2, syn, set_event_handler, [syn_test_event_handler_resolution]),
  1009. %% start syn on nodes
  1010. ok = syn:start(),
  1011. ok = rpc:call(SlaveNode1, syn, start, []),
  1012. ok = rpc:call(SlaveNode2, syn, start, []),
  1013. %% add scopes
  1014. ok = syn:add_node_to_scopes([scope_all]),
  1015. ok = rpc:call(SlaveNode1, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  1016. ok = rpc:call(SlaveNode2, syn, add_node_to_scopes, [[scope_all, scope_bc]]),
  1017. %% current node
  1018. TestPid = self(),
  1019. CurrentNode = node(),
  1020. %% partial netsplit (1 cannot see 2)
  1021. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1022. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1023. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1024. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1025. %% start conflict processes
  1026. PidOn1 = syn_test_suite_helper:start_process(SlaveNode1),
  1027. PidOn2 = syn_test_suite_helper:start_process(SlaveNode2),
  1028. %% --> conflict by netsplit
  1029. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom", PidOn1, {recipient, TestPid, keepthis}]),
  1030. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom", PidOn2, {recipient, TestPid, "meta-2"}]),
  1031. ok = rpc:call(SlaveNode1, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, {recipient, TestPid, keepthis}]),
  1032. ok = rpc:call(SlaveNode2, syn, register, [scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, {recipient, TestPid, "meta-2"}]),
  1033. %% check callbacks
  1034. syn_test_suite_helper:assert_received_messages([
  1035. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1036. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1037. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", normal},
  1038. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1039. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", normal},
  1040. {on_process_registered, SlaveNode1, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal},
  1041. {on_process_registered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, "meta-2", normal}
  1042. ]),
  1043. syn_test_suite_helper:assert_empty_queue(self()),
  1044. %% re-join
  1045. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1046. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1047. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1048. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1049. %% retrieve
  1050. syn_test_suite_helper:assert_wait(
  1051. {PidOn1, {recipient, TestPid, keepthis}},
  1052. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom") end
  1053. ),
  1054. syn_test_suite_helper:assert_wait(
  1055. {PidOn1, {recipient, TestPid, keepthis}},
  1056. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1057. ),
  1058. syn_test_suite_helper:assert_wait(
  1059. {PidOn1, {recipient, TestPid, keepthis}},
  1060. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1061. ),
  1062. 1 = syn:registry_count(scope_all),
  1063. 0 = syn:registry_count(scope_all, node()),
  1064. 1 = syn:registry_count(scope_all, SlaveNode1),
  1065. 0 = syn:registry_count(scope_all, SlaveNode2),
  1066. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1067. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1068. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1069. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1070. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1071. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1072. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1073. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1074. syn_test_suite_helper:assert_wait(
  1075. {PidOn1, {recipient, TestPid, keepthis}},
  1076. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1077. ),
  1078. syn_test_suite_helper:assert_wait(
  1079. {PidOn1, {recipient, TestPid, keepthis}},
  1080. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1081. ),
  1082. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc]),
  1083. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, node()]),
  1084. 1 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode1]),
  1085. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_bc, SlaveNode2]),
  1086. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc]),
  1087. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, node()]),
  1088. 1 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode1]),
  1089. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_bc, SlaveNode2]),
  1090. syn_test_suite_helper:assert_received_messages([
  1091. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1092. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, syn_conflict_resolution},
  1093. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1094. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, syn_conflict_resolution},
  1095. {on_process_unregistered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn2, "meta-2", syn_conflict_resolution},
  1096. {on_process_registered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, syn_conflict_resolution}
  1097. ]),
  1098. syn_test_suite_helper:assert_empty_queue(self()),
  1099. %% process alive (discarded process does not get killed with a custom handler)
  1100. syn_test_suite_helper:assert_wait(
  1101. true,
  1102. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1103. ),
  1104. syn_test_suite_helper:assert_wait(
  1105. true,
  1106. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1107. ),
  1108. %% clean up default scope
  1109. syn:unregister(scope_all, "proc-confict-by-netsplit-custom"),
  1110. ok = rpc:call(SlaveNode1, syn, unregister, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]),
  1111. %% retrieve
  1112. syn_test_suite_helper:assert_wait(
  1113. undefined,
  1114. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom") end
  1115. ),
  1116. syn_test_suite_helper:assert_wait(
  1117. undefined,
  1118. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1119. ),
  1120. syn_test_suite_helper:assert_wait(
  1121. undefined,
  1122. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom"]) end
  1123. ),
  1124. syn_test_suite_helper:assert_wait(
  1125. undefined,
  1126. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1127. ),
  1128. syn_test_suite_helper:assert_wait(
  1129. undefined,
  1130. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_bc, "proc-confict-by-netsplit-scoped-custom"]) end
  1131. ),
  1132. %% check callbacks
  1133. syn_test_suite_helper:assert_received_messages([
  1134. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1135. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1136. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom", PidOn1, keepthis, normal},
  1137. {on_process_unregistered, SlaveNode1, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal},
  1138. {on_process_unregistered, SlaveNode2, scope_bc, "proc-confict-by-netsplit-scoped-custom", PidOn1, keepthis, normal}
  1139. ]),
  1140. syn_test_suite_helper:assert_empty_queue(self()),
  1141. %% --> conflict by netsplit, which returns invalid pid
  1142. %% partial netsplit (1 cannot see 2)
  1143. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1144. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1145. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1146. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1147. %% register with meta with no 'keepthis' element
  1148. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, {recipient, TestPid, "meta-1"}]),
  1149. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, {recipient, TestPid, "meta-2"}]),
  1150. %% check callbacks
  1151. syn_test_suite_helper:assert_received_messages([
  1152. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1153. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1154. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", normal},
  1155. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", normal},
  1156. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", normal}
  1157. ]),
  1158. syn_test_suite_helper:assert_empty_queue(self()),
  1159. %% re-join
  1160. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1161. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1162. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1163. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1164. %% retrieve (names get freed)
  1165. syn_test_suite_helper:assert_wait(
  1166. undefined,
  1167. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom-other-pid") end
  1168. ),
  1169. syn_test_suite_helper:assert_wait(
  1170. undefined,
  1171. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-other-pid"]) end
  1172. ),
  1173. syn_test_suite_helper:assert_wait(
  1174. undefined,
  1175. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-other-pid"]) end
  1176. ),
  1177. 0 = syn:registry_count(scope_all),
  1178. 0 = syn:registry_count(scope_all, node()),
  1179. 0 = syn:registry_count(scope_all, SlaveNode1),
  1180. 0 = syn:registry_count(scope_all, SlaveNode2),
  1181. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1182. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1183. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1184. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1185. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1186. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1187. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1188. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1189. %% check callbacks
  1190. syn_test_suite_helper:assert_received_messages([
  1191. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", syn_conflict_resolution},
  1192. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn1, "meta-1", syn_conflict_resolution},
  1193. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-other-pid", PidOn2, "meta-2", syn_conflict_resolution}
  1194. ]),
  1195. syn_test_suite_helper:assert_empty_queue(self()),
  1196. %% process alive (discarded process does not get killed with a custom handler)
  1197. syn_test_suite_helper:assert_wait(
  1198. true,
  1199. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1200. ),
  1201. syn_test_suite_helper:assert_wait(
  1202. true,
  1203. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1204. ),
  1205. %% --> conflict by netsplit, which crashes
  1206. %% partial netsplit (1 cannot see 2)
  1207. rpc:call(SlaveNode1, syn_test_suite_helper, disconnect_node, [SlaveNode2]),
  1208. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1209. syn_test_suite_helper:assert_cluster(SlaveNode1, [node()]),
  1210. syn_test_suite_helper:assert_cluster(SlaveNode2, [node()]),
  1211. %% register with meta with no 'crash' element
  1212. ok = rpc:call(SlaveNode1, syn, register, [scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, {recipient, TestPid, crash}]),
  1213. ok = rpc:call(SlaveNode2, syn, register, [scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, {recipient, TestPid, crash}]),
  1214. %% check callbacks
  1215. syn_test_suite_helper:assert_received_messages([
  1216. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1217. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1218. {on_process_registered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, normal},
  1219. {on_process_registered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, normal},
  1220. {on_process_registered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, normal}
  1221. ]),
  1222. syn_test_suite_helper:assert_empty_queue(self()),
  1223. %% re-join
  1224. rpc:call(SlaveNode1, syn_test_suite_helper, connect_node, [SlaveNode2]),
  1225. syn_test_suite_helper:assert_cluster(node(), [SlaveNode1, SlaveNode2]),
  1226. syn_test_suite_helper:assert_cluster(SlaveNode1, [node(), SlaveNode2]),
  1227. syn_test_suite_helper:assert_cluster(SlaveNode2, [node(), SlaveNode1]),
  1228. %% retrieve (names get freed)
  1229. syn_test_suite_helper:assert_wait(
  1230. undefined,
  1231. fun() -> syn:lookup(scope_all, "proc-confict-by-netsplit-custom-crash") end
  1232. ),
  1233. syn_test_suite_helper:assert_wait(
  1234. undefined,
  1235. fun() -> rpc:call(SlaveNode1, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-crash"]) end
  1236. ),
  1237. syn_test_suite_helper:assert_wait(
  1238. undefined,
  1239. fun() -> rpc:call(SlaveNode2, syn, lookup, [scope_all, "proc-confict-by-netsplit-custom-crash"]) end
  1240. ),
  1241. 0 = syn:registry_count(scope_all),
  1242. 0 = syn:registry_count(scope_all, node()),
  1243. 0 = syn:registry_count(scope_all, SlaveNode1),
  1244. 0 = syn:registry_count(scope_all, SlaveNode2),
  1245. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all]),
  1246. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, node()]),
  1247. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode1]),
  1248. 0 = rpc:call(SlaveNode1, syn, registry_count, [scope_all, SlaveNode2]),
  1249. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all]),
  1250. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, node()]),
  1251. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode1]),
  1252. 0 = rpc:call(SlaveNode2, syn, registry_count, [scope_all, SlaveNode2]),
  1253. %% check callbacks
  1254. syn_test_suite_helper:assert_received_messages([
  1255. {on_process_unregistered, CurrentNode, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, syn_conflict_resolution},
  1256. {on_process_unregistered, SlaveNode1, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn1, crash, syn_conflict_resolution},
  1257. {on_process_unregistered, SlaveNode2, scope_all, "proc-confict-by-netsplit-custom-crash", PidOn2, crash, syn_conflict_resolution}
  1258. ]),
  1259. syn_test_suite_helper:assert_empty_queue(self()),
  1260. %% process alive (discarded process does not get killed with a custom handler)
  1261. syn_test_suite_helper:assert_wait(
  1262. true,
  1263. fun() -> rpc:call(SlaveNode1, erlang, is_process_alive, [PidOn1]) end
  1264. ),
  1265. syn_test_suite_helper:assert_wait(
  1266. true,
  1267. fun() -> rpc:call(SlaveNode2, erlang, is_process_alive, [PidOn2]) end
  1268. ).
  1269. %% ===================================================================
  1270. %% Internal
  1271. %% ===================================================================
  1272. add_to_local_table(Scope, Name, Pid, Meta, Time, MRef) ->
  1273. TableByName = syn_backbone:get_table_name(syn_registry_by_name, Scope),
  1274. TableByPid = syn_backbone:get_table_name(syn_registry_by_pid, Scope),
  1275. syn_registry:add_to_local_table(Name, Pid, Meta, Time, MRef, TableByName, TableByPid).
  1276. remove_from_local_table(Scope, Name, Pid) ->
  1277. TableByName = syn_backbone:get_table_name(syn_registry_by_name, Scope),
  1278. TableByPid = syn_backbone:get_table_name(syn_registry_by_pid, Scope),
  1279. syn_registry:remove_from_local_table(Name, Pid, TableByName, TableByPid).