Skip to content

Commit

Permalink
Merge pull request #178 from kpribylov/fix/#172
Browse files Browse the repository at this point in the history
Fix issue #172
  • Loading branch information
uwiger authored Jan 13, 2020
2 parents b7b0748 + 5e87040 commit a94e138
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ script: "GPROC_DIST=true rebar get-deps compile eunit"
otp_release:
- 20.0
- 19.3
- 19.2
- 19.1
- 19.0
- 18.3
- 18.2.1
Expand Down
2 changes: 1 addition & 1 deletion src/gproc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,7 @@ handle_call({demonitor, {T,l,_} = Key, Ref, Pid}, _From, S)
[{K, Opts}] ->
Opts1 = gproc_lib:remove_monitor(Opts, Pid, Ref),
ets:insert(?TAB, {K, Opts1}),
case gproc_lib:does_pid_monitor(Pid, Opts) of
case gproc_lib:does_pid_monitor(Pid, Opts1) of
true ->
ok;
false ->
Expand Down
10 changes: 5 additions & 5 deletions src/gproc_lib.erl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ remove_monitors(Key, Pid, MPid) ->
[{_, r}] ->
[];
[{K, Opts}] when is_list(Opts) ->
case lists:keyfind(monitors, 1, Opts) of
case lists:keyfind(monitor, 1, Opts) of
false ->
[];
{_, Ms} ->
Ms1 = [{P,R} || {P,R} <- Ms,
Ms1 = [{P,R,T} || {P,R,T} <- Ms,
P =/= MPid],
NewMs = lists:keyreplace(monitors, 1, Opts, {monitors,Ms1}),
NewMs = lists:keyreplace(monitor, 1, Opts, {monitor,Ms1}),
ets:insert(?TAB, {K, NewMs}),
[{insert, [{{Pid,Key}, NewMs}]}]
end;
Expand All @@ -306,7 +306,7 @@ remove_monitors(Key, Pid, MPid) ->
end.

does_pid_monitor(Pid, Opts) ->
case lists:keyfind(monitors, 1, Opts) of
case lists:keyfind(monitor, 1, Opts) of
false ->
false;
{_, Ms} ->
Expand Down Expand Up @@ -393,7 +393,7 @@ select_monitors([], _, Acc) ->
Acc.

remove_monitor_pid([{monitor, Mons}|T], Pid) ->
[{monitors, [M || M <- Mons,
[{monitor, [M || M <- Mons,
element(1, M) =/= Pid]}|T];
remove_monitor_pid([H|T], Pid) ->
[H | remove_monitor_pid(T, Pid)];
Expand Down
19 changes: 19 additions & 0 deletions test/gproc_tests.erl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ reg_test_() ->
, ?_test(t_is_clean())
, {spawn, ?_test(?debugVal(t_monitor_follow()))}
, ?_test(t_is_clean())
, {spawn, ?_test(?debugVal(t_two_monitoring_processes_one_dies()))}
, ?_test(t_is_clean())
, {spawn, ?_test(?debugVal(t_monitor_demonitor()))}
, ?_test(t_is_clean())
, {spawn, ?_test(?debugVal(t_subscribe()))}
Expand Down Expand Up @@ -926,6 +928,23 @@ t_monitor_follow() ->
[exit(P,kill) || P <- [P1,P3]],
ok.

t_two_monitoring_processes_one_dies() ->
Name = ?T_NAME,
P = t_spawn_reg(Name),
Ref = gproc:monitor(Name),
{P2, R2} = spawn_monitor(fun() -> gproc:monitor(Name) end),
receive
{'DOWN', R2, process, P2, normal} -> ok
end,
exit(P, kill),
receive
M ->
?assertEqual({gproc, unreg, Ref, Name}, M)
after 1000 ->
error(timeout)
end
.

t_monitor_demonitor() ->
Name = ?T_NAME,
P1 = t_spawn(Selective = true),
Expand Down

0 comments on commit a94e138

Please sign in to comment.