Permalink
Browse files

Fix to close a tcp socket properly AND set explicit timeout to all te…

…st cases to make executing tests stable
  • Loading branch information...
1 parent 5f3ff89 commit 0d86e50dcbba077124681ff89c1a9cf64cb17ac4 @mocchira mocchira committed Feb 19, 2014
Showing with 61 additions and 53 deletions.
  1. +4 −3 src/leo_rpc.erl
  2. +3 −1 src/leo_rpc_client_conn.erl
  3. +1 −1 src/leo_rpc_client_sup.erl
  4. +2 −3 src/leo_rpc_server_listener.erl
  5. +51 −45 test/leo_rpc_tests.erl
View
@@ -230,20 +230,21 @@ exec_1(PodName, ParamsBin, Timeout) ->
case leo_pod:checkout(PodName) of
{ok, ServerRef} ->
try
+ % for debug
case catch gen_server:call(
- ServerRef, {request, ParamsBin}, Timeout) of
+ ServerRef, {request, ParamsBin}, infinity) of
{'EXIT', Cause} ->
{error, Cause};
Ret ->
Ret
end
after
- catch gen_server:call(ServerRef, cancel),
+ %gen_server:call(ServerRef, cancel, infinity),
leo_pod:checkin_async(PodName, ServerRef)
end;
_ ->
%% retry
- timer:sleep(50),
+ timer:sleep(500),
exec_1(PodName, ParamsBin, Timeout)
end.
@@ -85,13 +85,15 @@ handle_call({request, Req}, From, State) ->
exec(Req, From, State);
handle_call(cancel, _From, State) ->
- {reply, ok, State#state{pid_from = undefined}};
+ terminate(cancel, State),
+ {stop, cancel, ok, State#state{pid_from = undefined}};
handle_call(status,_From, #state{socket = Socket} = State) ->
Ret = (Socket /= undefined),
{reply, {ok, Ret}, State};
handle_call(stop, _From, State) ->
+ terminate(stop, State),
{stop, normal, ok, State};
handle_call(_Request, _From, State) ->
@@ -41,7 +41,7 @@
-define(DEF_POOL_SIZE, 32).
-define(DEF_POOL_BUF, 32).
-define(DEF_RPC_PORT, 13075).
--define(SHUTDOWN_WAITING_TIME, 2000).
+-define(SHUTDOWN_WAITING_TIME, 10000).
-define(MAX_RESTART, 5).
-define(MAX_TIME, 60).
@@ -78,9 +78,8 @@ accept(ListenSocket, State, Module, Active,
recv(false = Active, Socket, State, Module, Option) ->
- #tcp_server_params{recv_length = Length,
- recv_timeout = Timeout} = Option,
- case catch gen_tcp:recv(Socket, Length, Timeout) of
+ #tcp_server_params{recv_length = Length} = Option,
+ case catch gen_tcp:recv(Socket, Length) of
{ok, Data} ->
call(Active, Socket, Data, State, Module, Option);
{'EXIT', Reason} ->
View
@@ -56,48 +56,52 @@ teardown(_) ->
ok.
basic_(Node) ->
- %% "leo_rpc:call/4"
- Mod1 = 'leo_misc',
- Fun1 = 'get_value',
- Param1 = [{'a',1},{'b',2},{'c',3}],
- Param2 = <<"123">>,
-
- ?assertEqual(1, leo_rpc:call(Node, Mod1, Fun1, ['a', Param1, Param2])),
- ?assertEqual(2, leo_rpc:call(Node, Mod1, Fun1, ['b', Param1, Param2])),
- ?assertEqual(Param2, leo_rpc:call(Node, Mod1, Fun1, ['d', Param1, Param2])),
- ?assertEqual(true, is_integer(leo_rpc:call(Node, 'leo_date', 'clock', []))),
-
- %% "leo_rpc:async_call/4"
- RPCKey1 = leo_rpc:async_call(Node, Mod1, Fun1, ['a', Param1, Param2]),
- ?assertEqual({value, 1}, leo_rpc:nb_yield(RPCKey1)),
-
- RPCKey2 = leo_rpc:async_call(Node, Mod1, Fun1, ['b', Param1, Param2]),
- ?assertEqual({value, 2}, leo_rpc:nb_yield(RPCKey2)),
-
- RPCKey3 = leo_rpc:async_call(Node, Mod1, Fun1, ['d', Param1, Param2]),
- ?assertEqual({value, Param2}, leo_rpc:nb_yield(RPCKey3)),
-
- RPCKey4 = leo_rpc:async_call(Node, 'leo_date', 'clock', []),
- ?assertMatch({value, _}, leo_rpc:nb_yield(RPCKey4)),
-
- %% "leo_rpc:multicall/4"
- Nodes = [Node, Node],
- ?assertEqual({[1,1],[]}, leo_rpc:multicall(Nodes, Mod1, Fun1, ['a', Param1, Param2])),
- ?assertEqual({[2,2],[]}, leo_rpc:multicall(Nodes, Mod1, Fun1, ['b', Param1, Param2])),
- ?assertEqual({[Param2,Param2],[]}, leo_rpc:multicall(Nodes, Mod1, Fun1, ['d', Param1, Param2])),
- ?assertMatch({[_,_],[]}, leo_rpc:multicall(Nodes, 'leo_date', 'clock', [])),
-
- %% "leo_rpc:cast/4"
- ?assertEqual(true, leo_rpc:cast(Node, Mod1, Fun1, ['a', Param1, Param2])),
- ok.
+ {timeout, 15, begin
+ %% "leo_rpc:call/4"
+ Mod1 = 'leo_misc',
+ Fun1 = 'get_value',
+ Param1 = [{'a',1},{'b',2},{'c',3}],
+ Param2 = <<"123">>,
+
+ ?assertEqual(1, leo_rpc:call(Node, Mod1, Fun1, ['a', Param1, Param2])),
+ ?assertEqual(2, leo_rpc:call(Node, Mod1, Fun1, ['b', Param1, Param2])),
+ ?assertEqual(Param2, leo_rpc:call(Node, Mod1, Fun1, ['d', Param1, Param2])),
+ ?assertEqual(true, is_integer(leo_rpc:call(Node, 'leo_date', 'clock', []))),
+
+ %% "leo_rpc:async_call/4"
+ RPCKey1 = leo_rpc:async_call(Node, Mod1, Fun1, ['a', Param1, Param2]),
+ ?assertEqual({value, 1}, leo_rpc:nb_yield(RPCKey1)),
+
+ RPCKey2 = leo_rpc:async_call(Node, Mod1, Fun1, ['b', Param1, Param2]),
+ ?assertEqual({value, 2}, leo_rpc:nb_yield(RPCKey2)),
+
+ RPCKey3 = leo_rpc:async_call(Node, Mod1, Fun1, ['d', Param1, Param2]),
+ ?assertEqual({value, Param2}, leo_rpc:nb_yield(RPCKey3)),
+
+ RPCKey4 = leo_rpc:async_call(Node, 'leo_date', 'clock', []),
+ ?assertMatch({value, _}, leo_rpc:nb_yield(RPCKey4)),
+
+ %% "leo_rpc:multicall/4"
+ Nodes = [Node, Node],
+ ?assertEqual({[1,1],[]}, leo_rpc:multicall(Nodes, Mod1, Fun1, ['a', Param1, Param2])),
+ ?assertEqual({[2,2],[]}, leo_rpc:multicall(Nodes, Mod1, Fun1, ['b', Param1, Param2])),
+ ?assertEqual({[Param2,Param2],[]}, leo_rpc:multicall(Nodes, Mod1, Fun1, ['d', Param1, Param2])),
+ ?assertMatch({[_,_],[]}, leo_rpc:multicall(Nodes, 'leo_date', 'clock', [])),
+
+ %% "leo_rpc:cast/4"
+ ?assertEqual(true, leo_rpc:cast(Node, Mod1, Fun1, ['a', Param1, Param2])),
+ ok
+ end}.
tuple_(Node) ->
- %% a value type is tuple
- Params = [{ok, 1, 2}, 3, <<"name:LEO">>, <<"type:FS">>],
- Expected = list_to_tuple(Params),
- ?assertEqual(Expected, leo_rpc:call(Node, 'erlang', 'list_to_tuple', [Params])),
- ?assertMatch({_,_,_}, leo_rpc:call(Node, 'erlang', 'now', [])),
- ok.
+ {timeout, 15, begin
+ %% a value type is tuple
+ Params = [{ok, 1, 2}, 3, <<"name:LEO">>, <<"type:FS">>],
+ Expected = list_to_tuple(Params),
+ ?assertEqual(Expected, leo_rpc:call(Node, 'erlang', 'list_to_tuple', [Params])),
+ ?assertMatch({_,_,_}, leo_rpc:call(Node, 'erlang', 'now', [])),
+ ok
+ end}.
send_large_(Node) ->
{timeout, 15, begin
@@ -160,11 +164,13 @@ record_(Node) ->
end}.
others_(Node) ->
- %% Others
- ?assertMatch({_,_,_}, leo_rpc:call(Node, 'erlang', 'now', [])),
- ?assertEqual(pong, leo_rpc:ping(Node)),
- ?assertEqual('node_0@127.0.0.1', leo_rpc:node()),
- ok.
+ {timeout, 15, begin
+ %% Others
+ ?assertMatch({_,_,_}, leo_rpc:call(Node, 'erlang', 'now', [])),
+ ?assertEqual(pong, leo_rpc:ping(Node)),
+ ?assertEqual('node_0@127.0.0.1', leo_rpc:node()),
+ ok
+ end}.

0 comments on commit 0d86e50

Please sign in to comment.