Browse Source

Make `await_connect` timeout configurable. #143

Сергей Прохоров 7 years ago
parent
commit
ab88d7333c
3 changed files with 23 additions and 13 deletions
  1. 8 6
      test/epgsql_cast.erl
  2. 7 1
      test/epgsql_cth.erl
  3. 8 6
      test/epgsql_incremental.erl

+ 8 - 6
test/epgsql_cast.erl

@@ -20,28 +20,30 @@
 
 connect(Opts) ->
     Ref = epgsqla:connect(Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
 connect(Host, Opts) ->
     Ref = epgsqla:connect(Host, Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
 connect(Host, Username, Opts) ->
     Ref = epgsqla:connect(Host, Username, Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
 connect(Host, Username, Password, Opts) ->
     Ref = epgsqla:connect(Host, Username, Password, Opts),
     %% TODO connect timeout
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
-await_connect(Ref) ->
+await_connect(Ref, Opts0) ->
+    Opts = epgsql_cth:to_proplist(Opts0),
+    Timeout = proplists:get_value(timeout, Opts, 5000),
     receive
         {C, Ref, connected} ->
             {ok, C};
         {_C, Ref, Error = {error, _}} ->
             Error
-    after 5000 ->
+    after Timeout ->
             error(timeout)
     end.
 

+ 7 - 1
test/epgsql_cth.erl

@@ -3,7 +3,8 @@
 -export([
          init/2,
          terminate/1,
-         pre_init_per_suite/3
+         pre_init_per_suite/3,
+         to_proplist/1
         ]).
 
 -include_lib("common_test/include/ct.hrl").
@@ -221,3 +222,8 @@ ts_add({Mega, Sec, Micro}, Timeout) ->
     {V div 1000000000000,
      V div 1000000 rem 1000000,
      V rem 1000000}.
+
+to_proplist(List) when is_list(List) ->
+    List;
+to_proplist(Map) ->
+    maps:to_list(Map).

+ 8 - 6
test/epgsql_incremental.erl

@@ -19,27 +19,29 @@
 
 connect(Opts) ->
     Ref = epgsqli:connect(Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
 connect(Host, Opts) ->
     Ref = epgsqli:connect(Host, Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
 connect(Host, Username, Opts) ->
     Ref = epgsqli:connect(Host, Username, Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
 connect(Host, Username, Password, Opts) ->
     Ref = epgsqli:connect(Host, Username, Password, Opts),
-    await_connect(Ref).
+    await_connect(Ref, Opts).
 
-await_connect(Ref) ->
+await_connect(Ref, Opts0) ->
+    Opts = epgsql_cth:to_proplist(Opts0),
+    Timeout = proplists:get_value(timeout, Opts, 5000),
     receive
         {C, Ref, connected} ->
             {ok, C};
         {_C, Ref, Error = {error, _}} ->
             Error
-    after 5000 ->
+    after Timeout ->
             error(timeout)
     end.