diff options
| author | Michael Klishin <michael@clojurewerkz.org> | 2020-03-30 21:44:12 +0300 |
|---|---|---|
| committer | Michael Klishin <michael@clojurewerkz.org> | 2020-03-30 21:44:12 +0300 |
| commit | d37c265c7946e6e357f141ec717dd10c74e73d4e (patch) | |
| tree | bcd4ec32e1b474c7f26bde5eb06a0e0e4e97f597 | |
| parent | 807392e81b1840f90554ae8f9ff76f2a231fe671 (diff) | |
| download | rabbitmq-server-git-d37c265c7946e6e357f141ec717dd10c74e73d4e.tar.gz | |
unit_SUITE: extract tests for memory monitor and pg_local
| -rw-r--r-- | test/unit_SUITE.erl | 6 | ||||
| -rw-r--r-- | test/unit_pg_local_SUITE.erl | 114 | ||||
| -rw-r--r-- | test/unit_vm_memory_monitor_SUITE.erl | 10 |
3 files changed, 117 insertions, 13 deletions
diff --git a/test/unit_SUITE.erl b/test/unit_SUITE.erl index f1bf6d1241..3e8c586de9 100644 --- a/test/unit_SUITE.erl +++ b/test/unit_SUITE.erl @@ -50,9 +50,6 @@ groups() -> merge_operator_policy_definitions, priority_queue, rabbit_direct_extract_extra_auth_props, - {resource_monitor, [parallel], [ - parse_information_unit - ]}, {supervisor2, [], [ check_shutdown_stop, check_shutdown_ignored @@ -61,9 +58,6 @@ groups() -> unfold ]}, {sequential_tests, [], [ - pg_local, - pg_local_with_unexpected_deaths1, - pg_local_with_unexpected_deaths2, decrypt_start_app, decrypt_start_app_file, decrypt_start_app_undefined, diff --git a/test/unit_pg_local_SUITE.erl b/test/unit_pg_local_SUITE.erl new file mode 100644 index 0000000000..852abc57eb --- /dev/null +++ b/test/unit_pg_local_SUITE.erl @@ -0,0 +1,114 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% https://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2011-2020 VMware, Inc. or its affiliates. All rights reserved. +%% + +-module(unit_pg_local_SUITE). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-include_lib("rabbit_common/include/rabbit.hrl"). +-include_lib("rabbit_common/include/rabbit_framing.hrl"). + +-compile(export_all). + +all() -> + [ + {group, sequential_tests} + ]. + +groups() -> + [ + {sequential_tests, [], [ + pg_local, + pg_local_with_unexpected_deaths1, + pg_local_with_unexpected_deaths2 + ]} + ]. + + +pg_local(_Config) -> + [P, Q] = [spawn(fun () -> receive X -> X end end) || _ <- lists:seq(0, 1)], + check_pg_local(ok, [], []), + %% P joins group a, then b, then a again + check_pg_local(pg_local:join(a, P), [P], []), + check_pg_local(pg_local:join(b, P), [P], [P]), + check_pg_local(pg_local:join(a, P), [P, P], [P]), + %% Q joins group a, then b, then b again + check_pg_local(pg_local:join(a, Q), [P, P, Q], [P]), + check_pg_local(pg_local:join(b, Q), [P, P, Q], [P, Q]), + check_pg_local(pg_local:join(b, Q), [P, P, Q], [P, Q, Q]), + %% P leaves groups a and a + check_pg_local(pg_local:leave(a, P), [P, Q], [P, Q, Q]), + check_pg_local(pg_local:leave(b, P), [P, Q], [Q, Q]), + %% leave/2 is idempotent + check_pg_local(pg_local:leave(a, P), [Q], [Q, Q]), + check_pg_local(pg_local:leave(a, P), [Q], [Q, Q]), + %% clean up all processes + [begin X ! done, + Ref = erlang:monitor(process, X), + receive {'DOWN', Ref, process, X, _Info} -> ok end + end || X <- [P, Q]], + %% ensure the groups are empty + check_pg_local(ok, [], []), + passed. + +pg_local_with_unexpected_deaths1(_Config) -> + [A, B] = [spawn(fun () -> receive X -> X end end) || _ <- lists:seq(0, 1)], + check_pg_local(ok, [], []), + %% A joins groups a and b + check_pg_local(pg_local:join(a, A), [A], []), + check_pg_local(pg_local:join(b, A), [A], [A]), + %% B joins group b + check_pg_local(pg_local:join(b, B), [A], [A, B]), + + [begin erlang:exit(X, sleep_now_in_a_fire), + Ref = erlang:monitor(process, X), + receive {'DOWN', Ref, process, X, _Info} -> ok end + end || X <- [A, B]], + %% ensure the groups are empty + check_pg_local(ok, [], []), + ?assertNot(erlang:is_process_alive(A)), + ?assertNot(erlang:is_process_alive(B)), + + passed. + +pg_local_with_unexpected_deaths2(_Config) -> + [A, B] = [spawn(fun () -> receive X -> X end end) || _ <- lists:seq(0, 1)], + check_pg_local(ok, [], []), + %% A joins groups a and b + check_pg_local(pg_local:join(a, A), [A], []), + check_pg_local(pg_local:join(b, A), [A], [A]), + %% B joins group b + check_pg_local(pg_local:join(b, B), [A], [A, B]), + + %% something else yanks a record (or all of them) from the pg_local + %% bookkeeping table + ok = pg_local:clear(), + + [begin erlang:exit(X, sleep_now_in_a_fire), + Ref = erlang:monitor(process, X), + receive {'DOWN', Ref, process, X, _Info} -> ok end + end || X <- [A, B]], + %% ensure the groups are empty + check_pg_local(ok, [], []), + ?assertNot(erlang:is_process_alive(A)), + ?assertNot(erlang:is_process_alive(B)), + + passed. + +check_pg_local(ok, APids, BPids) -> + ok = pg_local:sync(), + ?assertEqual([true, true], [lists:sort(Pids) == lists:sort(pg_local:get_members(Key)) || + {Key, Pids} <- [{a, APids}, {b, BPids}]]). diff --git a/test/unit_vm_memory_monitor_SUITE.erl b/test/unit_vm_memory_monitor_SUITE.erl index 7c04946ce9..608d89ae6c 100644 --- a/test/unit_vm_memory_monitor_SUITE.erl +++ b/test/unit_vm_memory_monitor_SUITE.erl @@ -18,22 +18,18 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). --include_lib("rabbit_common/include/rabbit.hrl"). --include_lib("rabbit_common/include/rabbit_framing.hrl"). -compile(export_all). all() -> [ - {group, parallel_tests} + {group, sequential_tests} ]. groups() -> [ - {parallel_tests, [parallel], [ - {vm_memory_monitor, [parallel], [ - parse_line_linux - ]} + {sequential_tests, [], [ + parse_line_linux ]} ]. |
