Browse Source

Fix bug in handling unexpected gen_server calls

Also add test coverage for unexpected calls, casts, and info messages.
seth 13 years ago
parent
commit
7c61e90e18
2 changed files with 30 additions and 1 deletions
  1. 1 1
      src/pooler.erl
  2. 29 0
      test/pooler_test.erl

+ 1 - 1
src/pooler.erl

@@ -201,7 +201,7 @@ handle_call(pool_stats, _From, State) ->
 handle_call({cull_pool, PoolName, MaxAgeMin}, _From, State) ->
     {reply, ok, cull_members(PoolName, MaxAgeMin, State)};
 handle_call(_Request, _From, State) ->
-    {noreply, ok, State}.
+    {noreply, State}.
 
 -spec handle_cast(_,_) -> {'noreply', _}.
 handle_cast({return_member, Pid, Status, _CPid}, State) ->

+ 29 - 0
test/pooler_test.erl

@@ -285,6 +285,35 @@ pooler_basics_test_() ->
      ]}}.
 
 
+random_message_test_() ->
+    {setup,
+     fun() ->
+             Pools = [[{name, "p1"},
+                       {max_count, 2},
+                       {init_count, 1},
+                       {start_mfa,
+                        {pooled_gs, start_link, [{"type-0"}]}}]],
+             application:set_env(pooler, pools, Pools),
+             error_logger:delete_report_handler(error_logger_tty_h),
+             application:start(pooler),
+             %% now send some bogus messages
+             %% do the call in a throw-away process to avoid timeout error
+             spawn(fun() -> catch gen_server:call(pooler, {unexpected_garbage_msg, 5}) end),
+             gen_server:cast(pooler, {unexpected_garbage_msg, 6}),
+            whereis(pooler) ! {unexpected_garbage_msg, 7},
+             ok
+     end,
+     fun(_) ->
+             application:stop(pooler)
+     end,
+    [
+     fun() ->
+             Pid = pooler:take_member("p1"),
+             {Type, _} =  pooled_gs:get_id(Pid),
+             ?assertEqual("type-0", Type)
+     end
+    ]}.
+
 pooler_integration_test_() ->
     {foreach,
      % setup