Browse Source

Add test to ensure conflicts are resolved by default.

Roberto Ostinelli 10 years ago
parent
commit
e7a71c40c4
1 changed files with 56 additions and 3 deletions
  1. 56 3
      test/syn_netsplits_SUITE.erl

+ 56 - 3
test/syn_netsplits_SUITE.erl

@@ -35,7 +35,8 @@
 
 %% tests
 -export([
-    two_nodes_netsplit_when_there_are_no_conflicts/1
+    two_nodes_netsplit_when_there_are_no_conflicts/1,
+    two_nodes_netsplit_when_there_are_conflicts/1
 ]).
 
 %% include
@@ -73,7 +74,8 @@ all() ->
 groups() ->
     [
         {two_nodes_netsplits, [shuffle], [
-            two_nodes_netsplit_when_there_are_no_conflicts
+            two_nodes_netsplit_when_there_are_no_conflicts,
+            two_nodes_netsplit_when_there_are_conflicts
         ]}
     ].
 %% -------------------------------------------------------------------
@@ -197,7 +199,7 @@ two_nodes_netsplit_when_there_are_no_conflicts(Config) ->
 
     %% reconnect
     syn_test_suite_helper:connect_node(SlaveNodeName),
-    timer:sleep(2000),
+    timer:sleep(1000),
 
     %% check tables
     3 = mnesia:table_info(syn_processes_table, size),
@@ -226,3 +228,54 @@ two_nodes_netsplit_when_there_are_no_conflicts(Config) ->
     syn_test_suite_helper:kill_process(LocalPid),
     syn_test_suite_helper:kill_process(SlavePidLocal),
     syn_test_suite_helper:kill_process(SlavePidSlave).
+
+two_nodes_netsplit_when_there_are_conflicts(Config) ->
+    %% get slave
+    SlaveNodeName = proplists:get_value(slave_node_name, Config),
+    CurrentNode = node(),
+
+    %% start processes
+    LocalPid = syn_test_suite_helper:start_process(),
+    SlavePid = syn_test_suite_helper:start_process(SlaveNodeName),
+
+    %% register
+    ok = syn:register(conflicting_key, SlavePid),
+    timer:sleep(100),
+
+    %% check tables
+    1 = mnesia:table_info(syn_processes_table, size),
+    1 = rpc:call(SlaveNodeName, mnesia, table_info, [syn_processes_table, size]),
+
+    %% check process
+    SlavePid = syn:find_by_key(conflicting_key),
+
+    %% simulate net split
+    syn_test_suite_helper:disconnect_node(SlaveNodeName),
+    timer:sleep(1000),
+
+    %% check tables
+    0 = mnesia:table_info(syn_processes_table, size),
+    [CurrentNode] = mnesia:table_info(syn_processes_table, active_replicas),
+
+    %% now register the local pid with the same key
+    ok = syn:register(conflicting_key, LocalPid),
+
+    %% check process
+    LocalPid = syn:find_by_key(conflicting_key),
+
+    %% reconnect
+    syn_test_suite_helper:connect_node(SlaveNodeName),
+    timer:sleep(1000),
+
+    %% check tables
+    1 = mnesia:table_info(syn_processes_table, size),
+    1 = rpc:call(SlaveNodeName, mnesia, table_info, [syn_processes_table, size]),
+
+    %% check process
+    FoundPid = syn:find_by_key(conflicting_key),
+
+    true = lists:member(FoundPid, [LocalPid, SlavePid]),
+
+    %% kill processes
+    syn_test_suite_helper:kill_process(LocalPid),
+    syn_test_suite_helper:kill_process(SlavePid).