syn_registry_consistency_SUITE.erl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. %% ==========================================================================================================
  2. %% Syn - A global Process Registry and Process Group manager.
  3. %%
  4. %% The MIT License (MIT)
  5. %%
  6. %% Copyright (c) 2015 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. -module(syn_registry_consistency_SUITE).
  26. %% callbacks
  27. -export([all/0]).
  28. -export([init_per_suite/1, end_per_suite/1]).
  29. -export([groups/0, init_per_group/2, end_per_group/2]).
  30. -export([init_per_testcase/2, end_per_testcase/2]).
  31. %% tests
  32. -export([
  33. two_nodes_netsplit_when_there_are_no_conflicts/1,
  34. two_nodes_netsplit_kill_resolution_when_there_are_conflicts/1,
  35. two_nodes_netsplit_callback_resolution_when_there_are_conflicts/1,
  36. two_nodes_netsplit_with_nodedown_when_there_are_no_conflicts/1
  37. ]).
  38. -export([
  39. three_nodes_netsplit_kill_resolution_when_there_are_conflicts/1
  40. ]).
  41. %% internal
  42. -export([process_reply_main/0]).
  43. -export([registry_conflicting_process_callback_dummy/3]).
  44. -export([wait_for_node_down_resume_and_reconnect/1]).
  45. %% include
  46. -include_lib("common_test/include/ct.hrl").
  47. %% ===================================================================
  48. %% Callbacks
  49. %% ===================================================================
  50. %% -------------------------------------------------------------------
  51. %% Function: all() -> GroupsAndTestCases | {skip,Reason}
  52. %% GroupsAndTestCases = [{group,GroupName} | TestCase]
  53. %% GroupName = atom()
  54. %% TestCase = atom()
  55. %% Reason = term()
  56. %% -------------------------------------------------------------------
  57. all() ->
  58. [
  59. {group, two_nodes_netsplits},
  60. {group, three_nodes_netsplits}
  61. ].
  62. %% -------------------------------------------------------------------
  63. %% Function: groups() -> [Group]
  64. %% Group = {GroupName,Properties,GroupsAndTestCases}
  65. %% GroupName = atom()
  66. %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
  67. %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
  68. %% TestCase = atom()
  69. %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
  70. %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
  71. %% repeat_until_any_ok | repeat_until_any_fail
  72. %% N = integer() | forever
  73. %% -------------------------------------------------------------------
  74. groups() ->
  75. [
  76. {two_nodes_netsplits, [shuffle], [
  77. two_nodes_netsplit_when_there_are_no_conflicts,
  78. two_nodes_netsplit_kill_resolution_when_there_are_conflicts,
  79. two_nodes_netsplit_callback_resolution_when_there_are_conflicts,
  80. two_nodes_netsplit_with_nodedown_when_there_are_no_conflicts
  81. ]},
  82. {three_nodes_netsplits, [shuffle], [
  83. three_nodes_netsplit_kill_resolution_when_there_are_conflicts
  84. ]}
  85. ].
  86. %% -------------------------------------------------------------------
  87. %% Function: init_per_suite(Config0) ->
  88. %% Config1 | {skip,Reason} |
  89. %% {skip_and_save,Reason,Config1}
  90. %% Config0 = Config1 = [tuple()]
  91. %% Reason = term()
  92. %% -------------------------------------------------------------------
  93. init_per_suite(Config) ->
  94. %% init
  95. SlaveNodeShortName = syn_slave,
  96. %% start slave
  97. {ok, SlaveNode} = syn_test_suite_helper:start_slave(SlaveNodeShortName),
  98. %% config
  99. [
  100. {slave_node_short_name, SlaveNodeShortName},
  101. {slave_node, SlaveNode}
  102. | Config
  103. ].
  104. %% -------------------------------------------------------------------
  105. %% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
  106. %% Config0 = Config1 = [tuple()]
  107. %% -------------------------------------------------------------------
  108. end_per_suite(Config) ->
  109. %% get slave node name
  110. SlaveNodeShortName = proplists:get_value(slave_node_short_name, Config),
  111. %% stop slave
  112. syn_test_suite_helper:stop_slave(SlaveNodeShortName).
  113. %% -------------------------------------------------------------------
  114. %% Function: init_per_group(GroupName, Config0) ->
  115. %% Config1 | {skip,Reason} |
  116. %% {skip_and_save,Reason,Config1}
  117. %% GroupName = atom()
  118. %% Config0 = Config1 = [tuple()]
  119. %% Reason = term()
  120. %% -------------------------------------------------------------------
  121. init_per_group(three_nodes_netsplits, Config) ->
  122. %% init
  123. SlaveNode2ShortName = syn_slave_2,
  124. %% start slave 2
  125. {ok, SlaveNode2} = syn_test_suite_helper:start_slave(SlaveNode2ShortName),
  126. %% config
  127. [
  128. {slave_node_2_short_name, SlaveNode2ShortName},
  129. {slave_node_2, SlaveNode2}
  130. | Config
  131. ];
  132. init_per_group(_GroupName, Config) -> Config.
  133. %% -------------------------------------------------------------------
  134. %% Function: end_per_group(GroupName, Config0) ->
  135. %% void() | {save_config,Config1}
  136. %% GroupName = atom()
  137. %% Config0 = Config1 = [tuple()]
  138. %% -------------------------------------------------------------------
  139. end_per_group(three_nodes_netsplits, Config) ->
  140. %% get slave node 2 name
  141. SlaveNode2ShortName = proplists:get_value(slave_node_2_short_name, Config),
  142. %% stop slave
  143. syn_test_suite_helper:stop_slave(SlaveNode2ShortName);
  144. end_per_group(_GroupName, _Config) -> ok.
  145. % ----------------------------------------------------------------------------------------------------------
  146. % Function: init_per_testcase(TestCase, Config0) ->
  147. % Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
  148. % TestCase = atom()
  149. % Config0 = Config1 = [tuple()]
  150. % Reason = term()
  151. % ----------------------------------------------------------------------------------------------------------
  152. init_per_testcase(_TestCase, Config) ->
  153. %% get slave
  154. SlaveNode = proplists:get_value(slave_node, Config),
  155. %% set schema location
  156. application:set_env(mnesia, schema_location, ram),
  157. rpc:call(SlaveNode, mnesia, schema_location, [ram]),
  158. %% return
  159. Config.
  160. % ----------------------------------------------------------------------------------------------------------
  161. % Function: end_per_testcase(TestCase, Config0) ->
  162. % void() | {save_config,Config1} | {fail,Reason}
  163. % TestCase = atom()
  164. % Config0 = Config1 = [tuple()]
  165. % Reason = term()
  166. % ----------------------------------------------------------------------------------------------------------
  167. end_per_testcase(_TestCase, Config) ->
  168. %% get slave
  169. SlaveNode = proplists:get_value(slave_node, Config),
  170. syn_test_suite_helper:clean_after_test(SlaveNode).
  171. %% ===================================================================
  172. %% Tests
  173. %% ===================================================================
  174. two_nodes_netsplit_when_there_are_no_conflicts(Config) ->
  175. %% get slave
  176. SlaveNode = proplists:get_value(slave_node, Config),
  177. CurrentNode = node(),
  178. %% start syn
  179. ok = syn:start(),
  180. ok = syn:init(),
  181. ok = rpc:call(SlaveNode, syn, start, []),
  182. ok = rpc:call(SlaveNode, syn, init, []),
  183. timer:sleep(100),
  184. %% start processes
  185. LocalPid = syn_test_suite_helper:start_process(),
  186. SlavePidLocal = syn_test_suite_helper:start_process(SlaveNode),
  187. SlavePidSlave = syn_test_suite_helper:start_process(SlaveNode),
  188. %% register
  189. ok = syn:register(local_pid, LocalPid),
  190. ok = syn:register(slave_pid_local, SlavePidLocal), %% slave registered on local node
  191. ok = rpc:call(SlaveNode, syn, register, [slave_pid_slave, SlavePidSlave]), %% slave registered on slave node
  192. timer:sleep(100),
  193. %% check tables
  194. 3 = mnesia:table_info(syn_registry_table, size),
  195. 3 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  196. LocalActiveReplicas = mnesia:table_info(syn_registry_table, active_replicas),
  197. 2 = length(LocalActiveReplicas),
  198. true = lists:member(SlaveNode, LocalActiveReplicas),
  199. true = lists:member(CurrentNode, LocalActiveReplicas),
  200. SlaveActiveReplicas = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, active_replicas]),
  201. 2 = length(SlaveActiveReplicas),
  202. true = lists:member(SlaveNode, SlaveActiveReplicas),
  203. true = lists:member(CurrentNode, SlaveActiveReplicas),
  204. %% simulate net split
  205. syn_test_suite_helper:disconnect_node(SlaveNode),
  206. timer:sleep(1000),
  207. %% check tables
  208. 1 = mnesia:table_info(syn_registry_table, size),
  209. [CurrentNode] = mnesia:table_info(syn_registry_table, active_replicas),
  210. %% reconnect
  211. syn_test_suite_helper:connect_node(SlaveNode),
  212. timer:sleep(1000),
  213. %% check tables
  214. 3 = mnesia:table_info(syn_registry_table, size),
  215. 3 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  216. LocalActiveReplicas2 = mnesia:table_info(syn_registry_table, active_replicas),
  217. 2 = length(LocalActiveReplicas2),
  218. true = lists:member(SlaveNode, LocalActiveReplicas2),
  219. true = lists:member(CurrentNode, LocalActiveReplicas2),
  220. SlaveActiveReplicas2 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, active_replicas]),
  221. 2 = length(SlaveActiveReplicas2),
  222. true = lists:member(SlaveNode, SlaveActiveReplicas2),
  223. true = lists:member(CurrentNode, SlaveActiveReplicas2),
  224. %% check processes
  225. LocalPid = syn:find_by_key(local_pid),
  226. SlavePidLocal = syn:find_by_key(slave_pid_local),
  227. SlavePidSlave = syn:find_by_key(slave_pid_slave),
  228. LocalPid = rpc:call(SlaveNode, syn, find_by_key, [local_pid]),
  229. SlavePidLocal = rpc:call(SlaveNode, syn, find_by_key, [slave_pid_local]),
  230. SlavePidSlave = rpc:call(SlaveNode, syn, find_by_key, [slave_pid_slave]),
  231. %% kill processes
  232. syn_test_suite_helper:kill_process(LocalPid),
  233. syn_test_suite_helper:kill_process(SlavePidLocal),
  234. syn_test_suite_helper:kill_process(SlavePidSlave).
  235. two_nodes_netsplit_kill_resolution_when_there_are_conflicts(Config) ->
  236. %% get slave
  237. SlaveNode = proplists:get_value(slave_node, Config),
  238. CurrentNode = node(),
  239. %% start syn
  240. ok = syn:start(),
  241. ok = syn:init(),
  242. ok = rpc:call(SlaveNode, syn, start, []),
  243. ok = rpc:call(SlaveNode, syn, init, []),
  244. timer:sleep(100),
  245. %% start processes
  246. LocalPid = syn_test_suite_helper:start_process(),
  247. SlavePid = syn_test_suite_helper:start_process(SlaveNode),
  248. %% register
  249. ok = syn:register(conflicting_key, SlavePid),
  250. timer:sleep(100),
  251. %% check tables
  252. 1 = mnesia:table_info(syn_registry_table, size),
  253. 1 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  254. %% check process
  255. SlavePid = syn:find_by_key(conflicting_key),
  256. %% simulate net split
  257. syn_test_suite_helper:disconnect_node(SlaveNode),
  258. timer:sleep(1000),
  259. %% check tables
  260. 0 = mnesia:table_info(syn_registry_table, size),
  261. [CurrentNode] = mnesia:table_info(syn_registry_table, active_replicas),
  262. %% now register the local pid with the same key
  263. ok = syn:register(conflicting_key, LocalPid),
  264. %% check process
  265. LocalPid = syn:find_by_key(conflicting_key),
  266. %% reconnect
  267. syn_test_suite_helper:connect_node(SlaveNode),
  268. timer:sleep(1000),
  269. %% check tables
  270. 1 = mnesia:table_info(syn_registry_table, size),
  271. 1 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  272. %% check process
  273. FoundPid = syn:find_by_key(conflicting_key),
  274. true = lists:member(FoundPid, [LocalPid, SlavePid]),
  275. %% kill processes
  276. syn_test_suite_helper:kill_process(LocalPid),
  277. syn_test_suite_helper:kill_process(SlavePid),
  278. %% unregister
  279. global:unregister_name(syn_consistency_SUITE_result).
  280. two_nodes_netsplit_callback_resolution_when_there_are_conflicts(Config) ->
  281. %% get slave
  282. SlaveNode = proplists:get_value(slave_node, Config),
  283. CurrentNode = node(),
  284. %% load configuration variables from syn-test.config => this sets the registry_conflicting_process_callback option
  285. syn_test_suite_helper:set_environment_variables(),
  286. syn_test_suite_helper:set_environment_variables(SlaveNode),
  287. %% start syn
  288. ok = syn:start(),
  289. ok = syn:init(),
  290. ok = rpc:call(SlaveNode, syn, start, []),
  291. ok = rpc:call(SlaveNode, syn, init, []),
  292. timer:sleep(100),
  293. %% start processes
  294. LocalPid = syn_test_suite_helper:start_process(fun process_reply_main/0),
  295. SlavePid = syn_test_suite_helper:start_process(SlaveNode, fun process_reply_main/0),
  296. %% register global process
  297. ResultPid = self(),
  298. global:register_name(syn_consistency_SUITE_result, ResultPid),
  299. %% register
  300. Meta = {some, meta, data},
  301. ok = syn:register(conflicting_key, SlavePid, Meta),
  302. timer:sleep(100),
  303. %% check tables
  304. 1 = mnesia:table_info(syn_registry_table, size),
  305. 1 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  306. %% check process
  307. SlavePid = syn:find_by_key(conflicting_key),
  308. %% simulate net split
  309. syn_test_suite_helper:disconnect_node(SlaveNode),
  310. timer:sleep(1000),
  311. %% check tables
  312. 0 = mnesia:table_info(syn_registry_table, size),
  313. [CurrentNode] = mnesia:table_info(syn_registry_table, active_replicas),
  314. %% now register the local pid with the same key
  315. ok = syn:register(conflicting_key, LocalPid, Meta),
  316. %% check process
  317. LocalPid = syn:find_by_key(conflicting_key),
  318. %% reconnect
  319. syn_test_suite_helper:connect_node(SlaveNode),
  320. timer:sleep(1000),
  321. %% check tables
  322. 1 = mnesia:table_info(syn_registry_table, size),
  323. 1 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  324. %% check process
  325. FoundPid = syn:find_by_key(conflicting_key),
  326. true = lists:member(FoundPid, [LocalPid, SlavePid]),
  327. %% check message received from killed pid
  328. KilledPid = lists:nth(1, lists:delete(FoundPid, [LocalPid, SlavePid])),
  329. receive
  330. {exited, KilledPid, Meta} -> ok
  331. after 2000 ->
  332. ok = conflicting_process_did_not_receive_message
  333. end,
  334. %% kill processes
  335. syn_test_suite_helper:kill_process(LocalPid),
  336. syn_test_suite_helper:kill_process(SlavePid),
  337. %% unregister
  338. global:unregister_name(syn_consistency_SUITE_result).
  339. two_nodes_netsplit_with_nodedown_when_there_are_no_conflicts(Config) ->
  340. %% get slave
  341. SlaveNode = proplists:get_value(slave_node, Config),
  342. CurrentNode = node(),
  343. %% start syn
  344. ok = syn:start(),
  345. ok = syn:init(),
  346. ok = rpc:call(SlaveNode, syn, start, []),
  347. ok = rpc:call(SlaveNode, syn, init, []),
  348. timer:sleep(100),
  349. %% start processes
  350. LocalPid = syn_test_suite_helper:start_process(),
  351. SlavePidLocal = syn_test_suite_helper:start_process(SlaveNode),
  352. SlavePidSlave = syn_test_suite_helper:start_process(SlaveNode),
  353. %% register
  354. ok = syn:register(local_pid, LocalPid),
  355. ok = syn:register(slave_pid_local, SlavePidLocal), %% slave registered on local node
  356. ok = rpc:call(SlaveNode, syn, register, [slave_pid_slave, SlavePidSlave]), %% slave registered on slave node
  357. timer:sleep(100),
  358. %% check tables
  359. 3 = mnesia:table_info(syn_registry_table, size),
  360. 3 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  361. LocalActiveReplicas = mnesia:table_info(syn_registry_table, active_replicas),
  362. 2 = length(LocalActiveReplicas),
  363. true = lists:member(SlaveNode, LocalActiveReplicas),
  364. true = lists:member(CurrentNode, LocalActiveReplicas),
  365. SlaveActiveReplicas = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, active_replicas]),
  366. 2 = length(SlaveActiveReplicas),
  367. true = lists:member(SlaveNode, SlaveActiveReplicas),
  368. true = lists:member(CurrentNode, SlaveActiveReplicas),
  369. %% simulate net split
  370. ok = net_kernel:monitor_nodes(true),
  371. rpc:cast(SlaveNode, ?MODULE, wait_for_node_down_resume_and_reconnect, [node()]),
  372. receive
  373. {nodedown, SlaveNode} -> ok
  374. end,
  375. timer:sleep(1000),
  376. %% check tables
  377. 1 = mnesia:table_info(syn_registry_table, size),
  378. [CurrentNode] = mnesia:table_info(syn_registry_table, active_replicas),
  379. %% wait to be reconnected
  380. receive
  381. {nodeup, SlaveNode} -> ok
  382. end,
  383. timer:sleep(1000),
  384. %% check tables
  385. 3 = mnesia:table_info(syn_registry_table, size),
  386. 3 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  387. LocalActiveReplicas2 = mnesia:table_info(syn_registry_table, active_replicas),
  388. 2 = length(LocalActiveReplicas2),
  389. true = lists:member(SlaveNode, LocalActiveReplicas2),
  390. true = lists:member(CurrentNode, LocalActiveReplicas2),
  391. SlaveActiveReplicas2 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, active_replicas]),
  392. 2 = length(SlaveActiveReplicas2),
  393. true = lists:member(SlaveNode, SlaveActiveReplicas2),
  394. true = lists:member(CurrentNode, SlaveActiveReplicas2),
  395. %% check processes
  396. LocalPid = syn:find_by_key(local_pid),
  397. SlavePidLocal = syn:find_by_key(slave_pid_local),
  398. SlavePidSlave = syn:find_by_key(slave_pid_slave),
  399. LocalPid = rpc:call(SlaveNode, syn, find_by_key, [local_pid]),
  400. SlavePidLocal = rpc:call(SlaveNode, syn, find_by_key, [slave_pid_local]),
  401. SlavePidSlave = rpc:call(SlaveNode, syn, find_by_key, [slave_pid_slave]),
  402. %% kill processes
  403. syn_test_suite_helper:kill_process(LocalPid),
  404. syn_test_suite_helper:kill_process(SlavePidLocal),
  405. syn_test_suite_helper:kill_process(SlavePidSlave).
  406. three_nodes_netsplit_kill_resolution_when_there_are_conflicts(Config) ->
  407. %% get slaves
  408. SlaveNode = proplists:get_value(slave_node, Config),
  409. SlaveNode2 = proplists:get_value(slave_node_2, Config),
  410. CurrentNode = node(),
  411. %% start syn
  412. ok = syn:start(),
  413. ok = syn:init(),
  414. ok = rpc:call(SlaveNode, syn, start, []),
  415. ok = rpc:call(SlaveNode, syn, init, []),
  416. ok = rpc:call(SlaveNode2, syn, start, []),
  417. ok = rpc:call(SlaveNode2, syn, init, []),
  418. timer:sleep(100),
  419. %% start processes
  420. LocalPid = syn_test_suite_helper:start_process(),
  421. SlavePid = syn_test_suite_helper:start_process(SlaveNode),
  422. Slave2Pid = syn_test_suite_helper:start_process(SlaveNode2),
  423. %% register
  424. ok = syn:register(conflicting_key, SlavePid),
  425. ok = syn:register(slave_2_process, Slave2Pid),
  426. timer:sleep(100),
  427. %% check tables
  428. 2 = mnesia:table_info(syn_registry_table, size),
  429. 2 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  430. 2 = rpc:call(SlaveNode2, mnesia, table_info, [syn_registry_table, size]),
  431. %% check process
  432. SlavePid = syn:find_by_key(conflicting_key),
  433. %% simulate net split
  434. syn_test_suite_helper:disconnect_node(SlaveNode),
  435. timer:sleep(1000),
  436. %% check tables
  437. 1 = mnesia:table_info(syn_registry_table, size),
  438. 1 = rpc:call(SlaveNode2, mnesia, table_info, [syn_registry_table, size]),
  439. ActiveReplicaseDuringNetsplit = mnesia:table_info(syn_registry_table, active_replicas),
  440. true = lists:member(CurrentNode, ActiveReplicaseDuringNetsplit),
  441. true = lists:member(SlaveNode2, ActiveReplicaseDuringNetsplit),
  442. %% now register the local pid with the same conflicting key
  443. ok = syn:register(conflicting_key, LocalPid),
  444. %% check process
  445. LocalPid = syn:find_by_key(conflicting_key),
  446. %% reconnect
  447. syn_test_suite_helper:connect_node(SlaveNode),
  448. timer:sleep(1000),
  449. %% check tables
  450. 2 = mnesia:table_info(syn_registry_table, size),
  451. 2 = rpc:call(SlaveNode, mnesia, table_info, [syn_registry_table, size]),
  452. 2 = rpc:call(SlaveNode2, mnesia, table_info, [syn_registry_table, size]),
  453. %% check processes
  454. FoundPid = syn:find_by_key(conflicting_key),
  455. true = lists:member(FoundPid, [LocalPid, SlavePid]),
  456. Slave2Pid = syn:find_by_key(slave_2_process),
  457. Slave2Pid = rpc:call(SlaveNode, syn, find_by_key, [slave_2_process]),
  458. Slave2Pid = rpc:call(SlaveNode2, syn, find_by_key, [slave_2_process]),
  459. %% kill processes
  460. syn_test_suite_helper:kill_process(LocalPid),
  461. syn_test_suite_helper:kill_process(SlavePid),
  462. syn_test_suite_helper:kill_process(Slave2Pid).
  463. %% ===================================================================
  464. %% Internal
  465. %% ===================================================================
  466. process_reply_main() ->
  467. receive
  468. {shutdown, Meta} ->
  469. timer:sleep(500), %% wait for global processes to propagate
  470. global:send(syn_consistency_SUITE_result, {exited, self(), Meta})
  471. end.
  472. registry_conflicting_process_callback_dummy(_Key, Pid, Meta) ->
  473. Pid ! {shutdown, Meta}.
  474. wait_for_node_down_resume_and_reconnect(Node) ->
  475. monitor_node(Node, true),
  476. ok = sys:suspend(net_kernel),
  477. receive
  478. {nodedown, Node} ->
  479. timer:sleep(1000),
  480. sys:resume(net_kernel),
  481. net_kernel:connect_node(Node)
  482. end.