Browse Source

Fix parameter ordering issue in mreg(, g, ) calls

The code currently throws an exception for any mreg() against a global
scoped object.  This is due to a parameter ordering issue on the
internal call to gproc_lib:insert_many().  Fix this ordering, and add
an unit test to ensure mreg() works in the future.

Signed-off-by: Gregory Haskins <ghaskins@novell.com>
Gregory Haskins 14 years ago
parent
commit
2928ba462f
2 changed files with 21 additions and 1 deletions
  1. 1 1
      src/gproc_dist.erl
  2. 20 0
      test/gproc_dist_tests.erl

+ 1 - 1
src/gproc_dist.erl

@@ -257,7 +257,7 @@ handle_leader_call({give_away, {T,g,_} = K, To, Pid}, _From, S, _E)
     end;
 handle_leader_call({mreg, T, g, L, Pid}, _From, S, _E) ->
     if T==p; T==n ->
-	    try gproc_lib:insert_many(T, g, Pid, L) of
+	    try gproc_lib:insert_many(T, g, L, Pid) of
 		{true,Objs} -> {reply, true, [{insert,Objs}], S};
 		false       -> {reply, badarg, S}
 	    catch

+ 20 - 0
test/gproc_dist_tests.erl

@@ -41,6 +41,9 @@ dist_test_() ->
 			       	       ?debugVal(t_simple_reg(Ns))
 			       end,
 			       fun() ->
+			       	       ?debugVal(t_mreg(Ns))
+			       end,
+			       fun() ->
 			       	       ?debugVal(t_await_reg(Ns))
 			       end,
 			       fun() ->
@@ -59,6 +62,7 @@ dist_test_() ->
       }]}.
 
 -define(T_NAME, {n, g, {?MODULE, ?LINE}}).
+-define(T_KVL, [{foo, "foo"}, {bar, "bar"}]).
 
 t_simple_reg([H|_] = Ns) ->
     Name = ?T_NAME,
@@ -68,6 +72,11 @@ t_simple_reg([H|_] = Ns) ->
     ?assertMatch(ok, t_lookup_everywhere(Name, Ns, undefined)),
     ?assertMatch(ok, t_call(P, die)).
 
+t_mreg([H|_] = Ns) ->
+    Kvl = ?T_KVL,
+    P = t_spawn_mreg(H, Kvl),
+    ?assertMatch(ok, t_call(P, die)).
+
 t_await_reg([A,B|_]) ->
     Name = ?T_NAME,
     P = t_spawn(A),
@@ -173,6 +182,17 @@ t_spawn_reg(Node, Name) ->
 	{P, ok} -> P
     end.
 
+t_spawn_mreg(Node, KVL) ->
+    Me = self(),
+    spawn(Node, fun() ->
+			?assertMatch(true, gproc:mreg(p, g, KVL)),
+			Me ! {self(), ok},
+			t_loop()
+		end),
+    receive
+	{P, ok} -> P
+    end.
+
 t_call(P, Req) ->
     Ref = erlang:monitor(process, P),
     P ! {self(), Ref, Req},