Browse Source

replaced spawn_link and seperate registration call with t_spawn_reg. added gproc_test_lib:t_pool_contains_atleast/2

Bosky 11 years ago
parent
commit
04ba951f38
2 changed files with 15 additions and 14 deletions
  1. 9 0
      test/gproc_test_lib.erl
  2. 6 14
      test/gproc_tests.erl

+ 9 - 0
test/gproc_test_lib.erl

@@ -6,6 +6,7 @@
          t_spawn_mreg/2,
          t_call/2,
          t_loop/0, t_loop/1,
+	 t_pool_contains_atleast/2,
          got_msg/1, got_msg/2]).
 
 -include_lib("eunit/include/eunit.hrl").
@@ -124,3 +125,11 @@ got_msg(Pb, Tag) ->
 			    erlang:error({timeout, got_msg, [Pb, Tag]})
 		    end
 	    end}).
+
+t_pool_contains_atleast(Pool,N)->
+    Existing = lists:foldl(fun({X,Y},Acc)->
+                                   Acc+1;
+                              (_,Acc) ->
+                                   Acc
+                           end, 0, gproc_pool:worker_pool(Pool) ),
+    Existing >= N.

+ 6 - 14
test/gproc_tests.erl

@@ -792,17 +792,7 @@ t_subscribe() ->
 t_simple_pool()->
     Key = p1w1,
     From = {n,l,Key},
-    P = spawn_link(fun() ->
-                      t_loop()
-              end),
-    P ! {self(), {reg, From}},
-    receive
-        {_,Registered} ->
-            ?assertEqual(Registered, true)
-    after 5000 ->
-            ?debugFmt("registration timeout ", []),
-            ok
-    end,
+    P = t_spawn_reg(From),
 
     %% create a new pool
     ?assertEqual(gproc_pool:new(p1), ok),
@@ -822,11 +812,12 @@ t_simple_pool()->
     ?assertEqual( length( gproc_pool:active_workers(p1)), 1),
     ?assertEqual( gproc_pool:pick(p1) , {n,l,[gproc_pool,p1,1,Key]}),
 
-    gproc:send(From, {self(), die}),
+    Ref = erlang:make_ref(),
+    gproc:send(From, {self(), Ref, die}),
     receive
-        {_,Returned}=X ->
+        {_, Ref, Returned}=X ->
             ?assertEqual(Returned, ok)
-    after 5000 ->
+    after 1000 ->
             %% the next 3 tests should fail if the worker is still alive
             ok
     end,
@@ -844,6 +835,7 @@ t_simple_pool()->
     %%       so relying on defined_workers
     ?assertEqual( length(gproc_pool:defined_workers(p1)), 0 ),
     ?assertEqual( length(gproc_pool:worker_pool(p1)), 0 ),
+    ?assertEqual( false, gproc_test_lib:t_pool_contains_atleast(p1,1) ),
 
     %% should be able to delete the pool now
     ?assertEqual( gproc_pool:delete(p1), ok).