test(dsraft): run `t_join_leave_errors` case in tracing context

This commit is contained in:
Andrew Mayorov 2024-07-12 18:28:24 +02:00
parent af81800aec
commit 2401a2fb80
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
1 changed files with 49 additions and 42 deletions

View File

@ -327,57 +327,64 @@ t_join_leave_errors('end', Config) ->
t_join_leave_errors(Config) -> t_join_leave_errors(Config) ->
%% This testcase verifies that logical errors arising during handling of %% This testcase verifies that logical errors arising during handling of
%% join/leave operations are reported correctly. %% join/leave operations are reported correctly.
DB = ?FUNCTION_NAME,
[N1, N2] = ?config(nodes, Config), [N1, N2] = ?config(nodes, Config),
Opts = opts(Config, #{n_shards => 16, n_sites => 1, replication_factor => 3}), Opts = opts(Config, #{n_shards => 16, n_sites => 1, replication_factor => 3}),
?assertEqual(ok, erpc:call(N1, emqx_ds, open_db, [?FUNCTION_NAME, Opts])),
?assertEqual(ok, erpc:call(N2, emqx_ds, open_db, [?FUNCTION_NAME, Opts])),
[S1, S2] = [ds_repl_meta(N, this_site) || N <- [N1, N2]], ?check_trace(
begin
?assertEqual(ok, erpc:call(N1, emqx_ds, open_db, [DB, Opts])),
?assertEqual(ok, erpc:call(N2, emqx_ds, open_db, [DB, Opts])),
?assertEqual(lists:sort([S1, S2]), lists:sort(ds_repl_meta(N1, db_sites, [?FUNCTION_NAME]))), [S1, S2] = [ds_repl_meta(N, this_site) || N <- [N1, N2]],
%% Attempts to join a nonexistent DB / site. ?assertEqual(
?assertEqual( lists:sort([S1, S2]), lists:sort(ds_repl_meta(N1, db_sites, [DB]))
{error, {nonexistent_db, boo}}, ),
ds_repl_meta(N1, join_db_site, [_DB = boo, S1])
),
?assertEqual(
{error, {nonexistent_sites, [<<"NO-MANS-SITE">>]}},
ds_repl_meta(N1, join_db_site, [?FUNCTION_NAME, <<"NO-MANS-SITE">>])
),
%% NOTE: Leaving a non-existent site is not an error.
?assertEqual(
{ok, unchanged},
ds_repl_meta(N1, leave_db_site, [?FUNCTION_NAME, <<"NO-MANS-SITE">>])
),
%% Should be no-op. %% Attempts to join a nonexistent DB / site.
?assertEqual({ok, unchanged}, ds_repl_meta(N1, join_db_site, [?FUNCTION_NAME, S1])), ?assertEqual(
?assertEqual([], emqx_ds_test_helpers:transitions(N1, ?FUNCTION_NAME)), {error, {nonexistent_db, boo}},
ds_repl_meta(N1, join_db_site, [_DB = boo, S1])
),
?assertEqual(
{error, {nonexistent_sites, [<<"NO-MANS-SITE">>]}},
ds_repl_meta(N1, join_db_site, [DB, <<"NO-MANS-SITE">>])
),
%% NOTE: Leaving a non-existent site is not an error.
?assertEqual(
{ok, unchanged},
ds_repl_meta(N1, leave_db_site, [DB, <<"NO-MANS-SITE">>])
),
%% Leave S2: %% Should be no-op.
?assertEqual( ?assertEqual({ok, unchanged}, ds_repl_meta(N1, join_db_site, [DB, S1])),
{ok, [S1]}, ?assertEqual([], emqx_ds_test_helpers:transitions(N1, DB)),
ds_repl_meta(N1, leave_db_site, [?FUNCTION_NAME, S2])
),
%% Impossible to leave the last site:
?assertEqual(
{error, {too_few_sites, []}},
ds_repl_meta(N1, leave_db_site, [?FUNCTION_NAME, S1])
),
%% "Move" the DB to the other node. %% Leave S2:
?assertMatch({ok, _}, ds_repl_meta(N1, join_db_site, [?FUNCTION_NAME, S2])), ?assertEqual(
?assertMatch({ok, _}, ds_repl_meta(N2, leave_db_site, [?FUNCTION_NAME, S1])), {ok, [S1]},
?assertMatch([_ | _], emqx_ds_test_helpers:transitions(N1, ?FUNCTION_NAME)), ds_repl_meta(N1, leave_db_site, [DB, S2])
?retry( ),
1000, 20, ?assertEqual([], emqx_ds_test_helpers:transitions(N1, ?FUNCTION_NAME)) %% Impossible to leave the last site:
), ?assertEqual(
{error, {too_few_sites, []}},
ds_repl_meta(N1, leave_db_site, [DB, S1])
),
%% Should be no-op. %% "Move" the DB to the other node.
?assertMatch({ok, _}, ds_repl_meta(N2, leave_db_site, [?FUNCTION_NAME, S1])), ?assertMatch({ok, _}, ds_repl_meta(N1, join_db_site, [DB, S2])),
?assertEqual([], emqx_ds_test_helpers:transitions(N1, ?FUNCTION_NAME)). ?assertMatch({ok, _}, ds_repl_meta(N2, leave_db_site, [DB, S1])),
?retry(
1000, 20, ?assertEqual([], emqx_ds_test_helpers:transitions(N1, DB))
),
%% Should be no-op.
?assertMatch({ok, _}, ds_repl_meta(N2, leave_db_site, [DB, S1])),
?assertEqual([], emqx_ds_test_helpers:transitions(N1, DB))
end,
[]
).
t_rebalance_chaotic_converges(init, Config) -> t_rebalance_chaotic_converges(init, Config) ->
Apps = [appspec(emqx_durable_storage), emqx_ds_builtin_raft], Apps = [appspec(emqx_durable_storage), emqx_ds_builtin_raft],