Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/pgsql_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
| {application_name, atom() | iodata()} % default: node()
| {timezone, iodata() | undefined} % default: undefined (not set)
| {async, pid()} % subscribe to notifications (default: no)
| {connection_timeout, integer()} % default: infinity
| proplists:property(). % undocumented !
-type open_options() :: [open_option()].
-type query_option() ::
Expand Down Expand Up @@ -450,7 +451,12 @@ unsubscribe(Pid, {pgsql_connection, ConnectionPid}) ->
%%
-spec start_link(open_options()) -> {ok, pid()} | {error, any()}.
start_link(Options) ->
gen_server:start_link(?MODULE, Options, []).
case lists:keytake(connection_timeout, 1, Options) of
false ->
gen_server:start_link(?MODULE, Options, []);
{value, {connection_timeout, Timeout}, ConnectionOptions} ->
gen_server:start_link(?MODULE, ConnectionOptions, [{timeout, Timeout}])
end.

%% ========================================================================= %%
%% gen_server API
Expand Down
10 changes: 10 additions & 0 deletions test/pgsql_connection_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ open_close_test_() ->
catch throw:{pgsql_error, _Error} ->
ok
end
end)},
{"Connection timeout",
?_test(begin
try
R = pgsql_connection:open("0.0.0.0", "test", "test", "", [{connection_timeout, 0}]),
pgsql_connection:close(R),
?assert(false)
catch throw:timeout ->
ok
end
end)}
]}.

Expand Down