Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
3685-pg-fix-pg-monitor_scope-0-1-return-value.p...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 3685-pg-fix-pg-monitor_scope-0-1-return-value.patch of Package erlang
From ef69cea0d7f71d8081f3c54ea1630776be01b5a0 Mon Sep 17 00:00:00 2001 From: Maxim Fedorov <maximfca@gmail.com> Date: Fri, 2 Sep 2022 13:47:07 -0700 Subject: [PATCH] [pg] fix pg:monitor_scope/0,1 return value These functions were expected to return the entire scope content, but due to a bug only local pids were returned. --- lib/kernel/src/pg.erl | 2 +- lib/kernel/test/pg_SUITE.erl | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/kernel/src/pg.erl b/lib/kernel/src/pg.erl index a44794e352..017b1942b4 100644 --- a/lib/kernel/src/pg.erl +++ b/lib/kernel/src/pg.erl @@ -305,7 +305,7 @@ handle_call({leave_local, Group, PidOrPids}, _From, #state{scope = Scope, local handle_call(monitor, {Pid, _Tag}, #state{scope = Scope, scope_monitors = ScopeMon} = State) -> %% next line could also be done with iterating over process state, but it appears to be slower - Local = maps:from_list([{G,P} || [G,P] <- ets:match(Scope, {'$1', '_', '$2'})]), + Local = maps:from_list([{G,P} || [G,P] <- ets:match(Scope, {'$1', '$2', '_'})]), MRef = erlang:monitor(process, Pid), %% monitor the monitor, to discard it upon termination, and generate MRef {reply, {MRef, Local}, State#state{scope_monitors = ScopeMon#{MRef => Pid}}}; diff --git a/lib/kernel/test/pg_SUITE.erl b/lib/kernel/test/pg_SUITE.erl index f735a3238a..423fc42a5a 100644 --- a/lib/kernel/test/pg_SUITE.erl +++ b/lib/kernel/test/pg_SUITE.erl @@ -55,6 +55,7 @@ disconnected_start/1, forced_sync/0, forced_sync/1, group_leave/1, + monitor_nonempty_scope/0, monitor_nonempty_scope/1, monitor_scope/0, monitor_scope/1, monitor/1 ]). @@ -83,7 +84,7 @@ groups() -> {cluster, [parallel], [process_owner_check, two, initial, netsplit, trisplit, foursplit, exchange, nolocal, double, scope_restart, missing_scope_join, empty_group_by_remote_leave, disconnected_start, forced_sync, group_leave]}, - {monitor, [parallel], [monitor_scope, monitor]} + {monitor, [parallel], [monitor_nonempty_scope, monitor_scope, monitor]} ]. %%-------------------------------------------------------------------- @@ -575,6 +576,27 @@ group_leave(Config) when is_list(Config) -> ?assertEqual([], pg:get_members(?FUNCTION_NAME, two)), ok. +monitor_nonempty_scope() -> + [{doc, "Ensure that monitor_scope returns full map of groups in the scope"}]. + +monitor_nonempty_scope(Config) when is_list(Config) -> + {Peer, Node} = spawn_node(?FUNCTION_NAME), + Pid = erlang:spawn_link(forever()), + RemotePid = erlang:spawn(Node, forever()), + Expected = lists:sort([Pid, RemotePid]), + pg:join(?FUNCTION_NAME, one, Pid), + ?assertEqual(ok, rpc:call(Node, pg, join, [?FUNCTION_NAME, one, RemotePid])), + %% Ensure that initial monitoring request returns current map of groups to pids + {Ref, #{one := Actual} = FullScope} = pg:monitor_scope(?FUNCTION_NAME), + ?assertEqual(Expected, Actual), + %% just in case - check there are no extra groups in that scope + ?assertEqual(1, map_size(FullScope)), + pg:demonitor(?FUNCTION_NAME, Ref), + %% re-check + {_Ref, FullScope} = pg:monitor_scope(?FUNCTION_NAME), + peer:stop(Peer), + exit(Pid, normal). + monitor_scope() -> [{doc, "Tests monitor_scope/1 and demonitor/2"}]. -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor