File 0986-mnesia-Add-a-test-case-mnesia_evil_coverage_test-add.patch of Package erlang

From 7d471290684979c2e68fff3b04b21ac63a537da3 Mon Sep 17 00:00:00 2001
From: Takeru Ohta <phjgt308@gmail.com>
Date: Tue, 31 May 2022 16:09:55 +0900
Subject: [PATCH 2/2] mnesia: Add a test case
 `mnesia_evil_coverage_test:add_copy_when_dst_going_down/1`

---
 lib/mnesia/test/mnesia_evil_coverage_test.erl | 53 ++++++++++++++++++-
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/lib/mnesia/test/mnesia_evil_coverage_test.erl b/lib/mnesia/test/mnesia_evil_coverage_test.erl
index 1c84774e6f..3d15da5ab1 100644
--- a/lib/mnesia/test/mnesia_evil_coverage_test.erl
+++ b/lib/mnesia/test/mnesia_evil_coverage_test.erl
@@ -30,7 +30,7 @@
 -export([system_info/1, table_info/1, error_description/1,
          db_node_lifecycle/1, evil_delete_db_node/1, start_and_stop/1,
          checkpoint/1, table_lifecycle/1, storage_options/1,
-         add_copy_conflict/1, add_copy_when_going_down/1,
+         add_copy_conflict/1, add_copy_when_going_down/1, add_copy_when_dst_going_down/1,
          add_copy_with_down/1,
          replica_management/1, clear_table_during_load/1,
          schema_availability/1, local_content/1,
@@ -66,7 +66,8 @@ all() ->
      db_node_lifecycle, evil_delete_db_node, start_and_stop,
      checkpoint, table_lifecycle, storage_options, 
      add_copy_conflict,
-     add_copy_when_going_down, add_copy_with_down, replica_management,
+     add_copy_when_going_down, add_copy_when_dst_going_down, add_copy_with_down,
+     replica_management,
      clear_table_during_load,
      schema_availability, local_content,
      {group, table_access_modifications}, replica_location,
@@ -735,6 +736,54 @@ add_copy_when_going_down(Config) ->
     ?match_receive({test,{aborted,_}}),
     ?verify_mnesia([Node2], []).
 
+add_copy_when_dst_going_down(suite) -> [];
+add_copy_when_dst_going_down(doc) ->
+    ["Table copy destination node goes down. Verify that the issue fixed in erlang/otp#6013 doesn't happen again, whitebox testing."];
+add_copy_when_dst_going_down(Config) ->
+    [Node1, Node2] = ?acquire_nodes(2, Config),
+    ?match({atomic, ok}, mnesia:create_table(a, [{ram_copies, [Node1]}])),
+    lists:foreach(fun(I) ->
+                          ok = mnesia:sync_dirty(fun() -> mnesia:write({a, I, I}) end)
+                  end,
+                  lists:seq(1, 100000)),
+    ?match({ok, _}, mnesia:change_config(extra_db_nodes, [Node2])),
+
+    %% Start table copy
+    Tester = self(),
+    spawn_link(fun() ->
+                       mnesia:add_table_copy(a, Node2, ram_copies),
+                       Tester ! add_table_copy_finished
+               end),
+    timer:sleep(10),  % Wait for `mnesia_loader:send_more/6` has started
+
+    %% Grab a write lock
+    spawn_link(fun() ->
+                       Fun = fun() ->
+                                     ok = mnesia:write_lock_table(a),
+                                     Tester ! {write_lock_acquired, self()},
+                                     receive node2_mnesia_killed -> ok
+                                     end,
+                                     Tester ! write_lock_released,
+                                     ok
+                             end,
+                       mnesia:transaction(Fun)
+               end),
+    receive {write_lock_acquired, Locker} -> ok
+    end,
+    timer:sleep(200),  % Wait for `mnesia_loader:send_more/6` has finished
+    ?match([], mnesia_test_lib:kill_mnesia([Node2])),
+    Locker ! node2_mnesia_killed,
+
+    receive write_lock_released -> ok
+    end,
+    receive add_table_copy_finished -> ok
+    end,
+    timer:sleep(1000),  % Wait for `mnesia_loader:finish_copy/5` has acquired the read lock
+
+    %% Grab a write lock
+    ?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:write_lock_table(a) end, 10)),
+    ?verify_mnesia([Node1], []).
+
 add_copy_with_down(suite) -> [];
 add_copy_with_down(Config) ->
     %% Allow add_table_copy() with ram_copies even all other replicas are down
-- 
2.35.3

openSUSE Build Service is sponsored by