Browse Source

Merge pull request #111 from ten0s/master

fix distributed monitor(Key, standby) when the name is not yet registered
Ulf Wiger 8 years ago
parent
commit
6d066d82ff
2 changed files with 15 additions and 1 deletions
  1. 4 1
      src/gproc_dist.erl
  2. 11 0
      test/gproc_dist_tests.erl

+ 4 - 1
src/gproc_dist.erl

@@ -1036,7 +1036,10 @@ pid_to_give_away_to({T,g,_} = Key) when T==n; T==a ->
 
 insert_reg([{_, Waiters}], K, Val, Pid, Event) ->
     gproc_lib:insert_reg(K, Val, Pid, g),
-    tell_waiters(Waiters, K, Pid, Val, Event).
+    tell_waiters(Waiters, K, Pid, Val, Event);
+insert_reg([], K, Val, Pid, Event) ->
+    gproc_lib:insert_reg(K, Val, Pid, g),
+    tell_waiters([], K, Val, Pid, Event).
 
 tell_waiters([{P,R}|T], K, Pid, V, Event) ->
     Msg = {gproc, R, registered, {K, Pid, V}},

+ 11 - 0
test/gproc_dist_tests.erl

@@ -85,6 +85,7 @@ basic_tests(Ns) ->
      ?f(t_sync(Ns)),
      ?f(t_monitor(Ns)),
      ?f(t_standby_monitor(Ns)),
+     ?f(t_standby_monitor_unreg(Ns)),
      ?f(t_follow_monitor(Ns)),
      ?f(t_subscribe(Ns))
     ].
@@ -473,6 +474,16 @@ t_standby_monitor([A,B|_] = Ns) ->
     ?assertMatch({gproc,unreg,Ref1,Na}, got_msg(Pc, gproc)),
     ?assertMatch(ok, t_lookup_everywhere(Na, Ns, undefined)).
 
+t_standby_monitor_unreg([A,B|_] = Ns) ->
+    Na = ?T_NAME,
+    Pa = t_spawn(A, _Selective = true),
+    Ref = t_call(Pa, {apply, gproc, monitor, [Na, standby]}),
+    ?assert(is_reference(Ref)),
+    ?assertMatch({gproc,{failover,Pa},Ref,Na}, got_msg(Pa, gproc)),
+    ?assertMatch(ok, t_lookup_everywhere(Na, Ns, Pa)),
+    ?assertMatch(ok, t_call(Pa, die)),
+    ?assertMatch(ok, t_lookup_everywhere(Na, Ns, undefined)).
+
 t_follow_monitor([A,B|_]) ->
     Na = ?T_NAME,
     Pa = t_spawn(A, _Selective = true),