aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mnesia/test')
-rw-r--r--lib/mnesia/test/mnesia_atomicity_test.erl18
-rw-r--r--lib/mnesia/test/mnesia_consistency_test.erl54
-rw-r--r--lib/mnesia/test/mnesia_dirty_access_test.erl56
-rw-r--r--lib/mnesia/test/mnesia_evil_backup.erl2
-rw-r--r--lib/mnesia/test/mnesia_recovery_test.erl11
-rw-r--r--lib/mnesia/test/mt.erl2
6 files changed, 95 insertions, 48 deletions
diff --git a/lib/mnesia/test/mnesia_atomicity_test.erl b/lib/mnesia/test/mnesia_atomicity_test.erl
index 612c4ad368..cc32ba3826 100644
--- a/lib/mnesia/test/mnesia_atomicity_test.erl
+++ b/lib/mnesia/test/mnesia_atomicity_test.erl
@@ -700,11 +700,19 @@ start_restart_check(RestartOp, ReplicaNeed, Config) ->
%% mnesia shall be killed at that node, where A is reading
%% the information from
- kill_where_to_read(TabName, N1, [N2, N3]),
+ Read = kill_where_to_read(TabName, N1, [N2, N3]),
%% wait some time to let mnesia go down and spread those news around
%% fun A shall be able to finish its job before being restarted
- wait(500),
+ Wait = fun(Loop) ->
+ wait(300),
+ sys:get_status(mnesia_monitor),
+ case lists:member(Read, mnesia_lib:val({current, db_nodes})) of
+ true -> Loop(Loop);
+ false -> ok
+ end
+ end,
+ Wait(Wait),
A ! go_ahead,
%% the sticky write doesnt work on remote nodes !!!
@@ -772,10 +780,12 @@ kill_where_to_read(TabName, N1, Nodes) ->
Read = rpc:call(N1,mnesia,table_info, [TabName, where_to_read]),
case lists:member(Read, Nodes) of
true ->
- mnesia_test_lib:kill_mnesia([Read]);
+ mnesia_test_lib:kill_mnesia([Read]),
+ Read;
false ->
?error("Fault while killing Mnesia: ~p~n", [Read]),
- mnesia_test_lib:kill_mnesia(Nodes)
+ mnesia_test_lib:kill_mnesia(Nodes),
+ Read
end.
sync_tid_release() ->
diff --git a/lib/mnesia/test/mnesia_consistency_test.erl b/lib/mnesia/test/mnesia_consistency_test.erl
index 9cc84de87b..2fe1bd34e6 100644
--- a/lib/mnesia/test/mnesia_consistency_test.erl
+++ b/lib/mnesia/test/mnesia_consistency_test.erl
@@ -665,10 +665,10 @@ consistency_after_restore(ReplicaType, Op, Config) ->
[lists:foreach(fun(E) -> ok = mnesia:dirty_write({Tab, E, 2}) end, NList) ||
Tab <- Tabs],
- Pids1 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carA, Op]), ok} || _ <- lists:seq(1, 5)],
- Pids2 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carB, Op]), ok} || _ <- lists:seq(1, 5)],
- Pids3 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carC, Op]), ok} || _ <- lists:seq(1, 5)],
- Pids4 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carD, Op]), ok} || _ <- lists:seq(1, 5)],
+ Pids1 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carA, Op]), carA} || _ <- lists:seq(1, 5)],
+ Pids2 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carB, Op]), carB} || _ <- lists:seq(1, 5)],
+ Pids3 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carC, Op]), carC} || _ <- lists:seq(1, 5)],
+ Pids4 = [{'EXIT', spawn_link(?MODULE, change_tab, [self(), carD, Op]), carD} || _ <- lists:seq(1, 5)],
AllPids = Pids1 ++ Pids2 ++ Pids3 ++ Pids4,
@@ -678,19 +678,38 @@ consistency_after_restore(ReplicaType, Op, Config) ->
Else -> Else
end
end,
-
+
timer:sleep(timer:seconds(Delay)), %% Let changers grab locks
?verbose("Doing restore~n", []),
?match(Tabs, Restore(File, [{default_op, Op}])),
- timer:sleep(timer:seconds(Delay)), %% Let em die
+ Collect = fun(Msg, Acc) ->
+ receive Msg -> Acc
+ after 10000 -> [Msg|Acc]
+ end
+ end,
- ?match_multi_receive(AllPids),
+ Failed1 = lists:foldl(Collect, [], AllPids),
+ Failed = lists:foldl(Collect, [], Failed1),
+
+ case Failed of
+ [] -> ok;
+ _ ->
+ ?match([], Failed),
+ io:format("TIME: ~p sec~n", [erlang:system_time(seconds) band 16#FF]),
+ Dbg = fun({_, Pid, Tab}) ->
+ io:format("Tab ~p: ~p~n",[Tab, process_info(Pid, current_stacktrace)]),
+ [io:format(" ~p~n", [Rec]) || Rec <- mnesia:dirty_match_object({Tab, '_', '_'})]
+ end,
+ [Dbg(Msg) || Msg <- Failed],
+ io:format(" Held: ~p~n", [mnesia_locker:get_held_locks()]),
+ io:format("Queue: ~p~n", [mnesia_locker:get_lock_queue()])
+ end,
- case ?match(ok, restore_verify_tabs(Tabs)) of
- {success, ok} ->
+ case ?match(ok, restore_verify_tabs(Tabs)) of
+ {success, ok} ->
file:delete(File);
- _ ->
+ _ ->
{T, M, S} = time(),
File2 = ?flat_format("consistency_error~w~w~w.BUP", [T, M, S]),
file:rename(File, File2)
@@ -700,17 +719,20 @@ consistency_after_restore(ReplicaType, Op, Config) ->
change_tab(Father, Tab, Test) ->
Key = rand:uniform(20),
Update = fun() ->
+ Time = erlang:system_time(seconds) band 16#FF,
+ case put(time, Time) of
+ Time -> ok;
+ _ -> io:format("~p ~p ~p sec~n", [self(), Tab, Time])
+ end,
case mnesia:read({Tab, Key}) of
- [{Tab, Key, 1}] ->
- quit;
- [{Tab, Key, _N}] ->
- mnesia:write({Tab, Key, 3})
+ [{Tab, Key, 1}] -> quit;
+ [{Tab, Key, _N}] -> mnesia:write({Tab, Key, 3})
end
end,
case mnesia:transaction(Update) of
{atomic, quit} ->
- exit(ok);
- {aborted, {no_exists, Tab}} when Test == recreate_tables ->%% I'll allow this
+ exit(Tab);
+ {aborted, {no_exists, Tab}} when Test == recreate_tables -> %% I'll allow this
change_tab(Father, Tab, Test);
{atomic, ok} ->
change_tab(Father, Tab, Test)
diff --git a/lib/mnesia/test/mnesia_dirty_access_test.erl b/lib/mnesia/test/mnesia_dirty_access_test.erl
index c9df8ed353..6d970ac990 100644
--- a/lib/mnesia/test/mnesia_dirty_access_test.erl
+++ b/lib/mnesia/test/mnesia_dirty_access_test.erl
@@ -461,77 +461,81 @@ dirty_index_update_set_xets(Config) when is_list(Config) ->
dirty_index_update_set(Config, ext_ets).
dirty_index_update_set(Config, Storage) ->
- [Node1] = Nodes = ?acquire_nodes(1, Config),
- Tab = index_test,
- ValPos = v1,
+ [Node1] = Nodes = ?acquire_nodes(1, Config),
+ Tab = index_test,
+ ValPos = v1,
ValPos2 = v3,
Def = [{attributes, [k, v1, v2, v3]},
{Storage, [Node1]},
- {index, [ValPos]}],
- ?match({atomic, ok}, mnesia:create_table(Tab, Def)),
-
+ {index, [ValPos]}],
+ ?match({atomic, ok}, mnesia:create_table(Tab, Def)),
+
Pat1 = {Tab, '$1', 2, '$2', '$3'},
- Pat2 = {Tab, '$1', '$2', '$3', '$4'},
-
- Rec1 = {Tab, 1, 2, 3, 4},
+ Pat2 = {Tab, '$1', '$2', '$3', '$4'},
+ Pat3 = {Tab, '_', '_', '_', {4, 14}},
+
+ Rec1 = {Tab, 1, 2, 3, {4, 14}},
Rec2 = {Tab, 2, 2, 13, 14},
- Rec3 = {Tab, 1, 12, 13, 14},
- Rec4 = {Tab, 4, 2, 13, 14},
-
+ Rec3 = {Tab, 1, 12, 13, 14},
+ Rec4 = {Tab, 4, 2, 13, 14},
+
?match([], mnesia:dirty_index_read(Tab, 2, ValPos)),
?match(ok, mnesia:dirty_write(Rec1)),
?match([Rec1], mnesia:dirty_index_read(Tab, 2, ValPos)),
-
+
?match(ok, mnesia:dirty_write(Rec2)),
R1 = mnesia:dirty_index_read(Tab, 2, ValPos),
?match([Rec1, Rec2], lists:sort(R1)),
-
+
?match(ok, mnesia:dirty_write(Rec3)),
R2 = mnesia:dirty_index_read(Tab, 2, ValPos),
?match([Rec2], lists:sort(R2)),
?match([Rec2], mnesia:dirty_index_match_object(Pat1, ValPos)),
-
- {atomic, R3} = mnesia:transaction(fun() -> mnesia:match_object(Pat2) end),
+
+ {atomic, R3} = mnesia:transaction(fun() -> mnesia:match_object(Pat2) end),
?match([Rec3, Rec2], lists:sort(R3)),
-
+
?match(ok, mnesia:dirty_write(Rec4)),
R4 = mnesia:dirty_index_read(Tab, 2, ValPos),
?match([Rec2, Rec4], lists:sort(R4)),
-
+
?match(ok, mnesia:dirty_delete({Tab, 4})),
?match([Rec2], mnesia:dirty_index_read(Tab, 2, ValPos)),
-
+
?match({atomic, ok}, mnesia:del_table_index(Tab, ValPos)),
?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:write(Rec4) end)),
?match({atomic, ok}, mnesia:add_table_index(Tab, ValPos)),
?match({atomic, ok}, mnesia:add_table_index(Tab, ValPos2)),
-
+
R5 = mnesia:dirty_match_object(Pat2),
?match([Rec3, Rec2, Rec4], lists:sort(R5)),
-
+
R6 = mnesia:dirty_index_read(Tab, 2, ValPos),
- ?match([Rec2, Rec4], lists:sort(R6)),
- ?match([], mnesia:dirty_index_read(Tab, 4, ValPos2)),
+ ?match([Rec2, Rec4], lists:sort(R6)),
+ ?match([], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)),
R7 = mnesia:dirty_index_read(Tab, 14, ValPos2),
?match([Rec3, Rec2, Rec4], lists:sort(R7)),
?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:write(Rec1) end)),
R8 = mnesia:dirty_index_read(Tab, 2, ValPos),
?match([Rec1, Rec2, Rec4], lists:sort(R8)),
- ?match([Rec1], mnesia:dirty_index_read(Tab, 4, ValPos2)),
+ ?match([Rec1], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)),
+ ?match([Rec1], mnesia:dirty_match_object(Pat3)),
+ ?match([Rec1], mnesia:dirty_index_match_object(Pat3, ValPos2)),
+
R9 = mnesia:dirty_index_read(Tab, 14, ValPos2),
?match([Rec2, Rec4], lists:sort(R9)),
?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:delete_object(Rec2) end)),
R10 = mnesia:dirty_index_read(Tab, 2, ValPos),
?match([Rec1, Rec4], lists:sort(R10)),
- ?match([Rec1], mnesia:dirty_index_read(Tab, 4, ValPos2)),
+ ?match([Rec1], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)),
?match([Rec4], mnesia:dirty_index_read(Tab, 14, ValPos2)),
?match(ok, mnesia:dirty_delete({Tab, 4})),
R11 = mnesia:dirty_index_read(Tab, 2, ValPos),
?match([Rec1], lists:sort(R11)),
- ?match([Rec1], mnesia:dirty_index_read(Tab, 4, ValPos2)),
+ ?match([Rec1], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)),
?match([], mnesia:dirty_index_read(Tab, 14, ValPos2)),
?verify_mnesia(Nodes, []).
diff --git a/lib/mnesia/test/mnesia_evil_backup.erl b/lib/mnesia/test/mnesia_evil_backup.erl
index b71348f144..e745ec9b04 100644
--- a/lib/mnesia/test/mnesia_evil_backup.erl
+++ b/lib/mnesia/test/mnesia_evil_backup.erl
@@ -325,7 +325,7 @@ restore(Config, Op) ->
end,
?match(ok, file:delete(File1)),
?match(ok, file:delete(File2)),
- ?match([], Check() -- Before),
+ ?match([], Check() -- (Before ++ [{ok, latest_log}, {ok, previous_log}])),
?verify_mnesia(Nodes, []).
diff --git a/lib/mnesia/test/mnesia_recovery_test.erl b/lib/mnesia/test/mnesia_recovery_test.erl
index 2388b595d0..130b87346f 100644
--- a/lib/mnesia/test/mnesia_recovery_test.erl
+++ b/lib/mnesia/test/mnesia_recovery_test.erl
@@ -504,12 +504,21 @@ with_checkpoint(Config, Type) when is_list(Config) ->
?match(ok, mnesia:deactivate_checkpoint(sune)),
?match([], check_chkp(Nodes)),
+ Wait = fun(Loop) ->
+ timer:sleep(300),
+ sys:get_status(mnesia_monitor),
+ case lists:member(Kill, mnesia_lib:val({current, db_nodes})) of
+ true -> Loop(Loop);
+ false -> ok
+ end
+ end,
+
case Kill of
Node1 ->
ignore;
Node2 ->
mnesia_test_lib:kill_mnesia([Kill]),
- timer:sleep(500), %% Just to help debugging
+ Wait(Wait),
?match({ok, sune, _}, mnesia:activate_checkpoint([{name, sune},
{max, mnesia:system_info(tables)},
{ram_overrides_dump, true}])),
diff --git a/lib/mnesia/test/mt.erl b/lib/mnesia/test/mt.erl
index 793fb125e6..5a981bf539 100644
--- a/lib/mnesia/test/mt.erl
+++ b/lib/mnesia/test/mt.erl
@@ -80,6 +80,8 @@ resolve(Suite0) when is_atom(Suite0) ->
{Suite, Case} ->
{Suite, is_group(Suite,Case)}
end;
+resolve({Suite0, {group, Case}}) ->
+ resolve({Suite0, Case});
resolve({Suite0, Case}) when is_atom(Suite0), is_atom(Case) ->
case alias(Suite0) of
Suite when is_atom(Suite) ->