Skip to content

Commit

Permalink
Increase timeout for login requests
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Feb 9, 2024
1 parent 2ee9da0 commit 8cf8f99
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/matrix_client/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule M51.MatrixClient.Client do
# Check the server supports password login
url = base_url <> "/_matrix/client/r0/login"
Logger.debug("(raw) GET #{url}")
response = httpoison.get!(url)
response = httpoison.get!(url, [], timeout: @timeout)
Logger.debug(Kernel.inspect(response))

case response do
Expand Down Expand Up @@ -111,7 +111,7 @@ defmodule M51.MatrixClient.Client do

url = base_url <> "/_matrix/client/r0/login"
Logger.debug("(raw) POST #{url} " <> Kernel.inspect(body))
response = httpoison.post!(url, body)
response = httpoison.post!(url, body, [], timeout: @timeout)
Logger.debug(Kernel.inspect(response))

case response do
Expand Down
30 changes: 21 additions & 9 deletions lib/matrix_client/poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,9 @@ defmodule M51.MatrixClient.Poller do
end

# Sends self JOIN, RPL_TOPIC/RPL_NOTOPIC, RPL_NAMREPLY
#
# Returns whether the announce was actually sent (ie. if the channel has a canonical
# alias, or was allowed to be sent without a canonical alias)
defp send_channel_welcome(
sup_pid,
room_id,
Expand All @@ -1172,15 +1175,20 @@ defmodule M51.MatrixClient.Poller do

supports_channel_rename = Enum.member?(capabilities, :channel_rename)

if old_canonical_alias == nil || !supports_channel_rename do
announce_new_channel(
M51.IrcConn.Supervisor,
sup_pid,
room_id,
write,
event
)
end
announced_new_channel =
if old_canonical_alias == nil || !supports_channel_rename do
announce_new_channel(
M51.IrcConn.Supervisor,
sup_pid,
room_id,
write,
event
)

true
else
false
end

if old_canonical_alias != nil do
if supports_channel_rename do
Expand All @@ -1197,6 +1205,8 @@ defmodule M51.MatrixClient.Poller do
command: "RENAME",
params: [old_canonical_alias, new_canonical_alias, "Canonical alias changed"]
})

true
else
close_renamed_channel(
sup_pid,
Expand All @@ -1205,6 +1215,8 @@ defmodule M51.MatrixClient.Poller do
canonical_alias_sender,
old_canonical_alias
)

announced_new_channel
end
end
end
Expand Down
42 changes: 32 additions & 10 deletions test/matrix_client/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule M51.MatrixClient.ClientTest do
setup :set_mox_from_context
setup :verify_on_exit!

@timeout 65000

setup do
start_supervised!({M51.MatrixClient.State, {self()}})

Expand All @@ -36,8 +38,10 @@ defmodule M51.MatrixClient.ClientTest do
assert url == "https://matrix.example.org/.well-known/matrix/client"
{:ok, %HTTPoison.Response{status_code: 404, body: "Error 404"}}
end)
|> expect(:get!, fn url ->
|> expect(:get!, fn url, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

%HTTPoison.Response{
status_code: 200,
Expand All @@ -46,8 +50,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}
end)
|> expect(:post!, fn url, body ->
|> expect(:post!, fn url, body, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

assert Jason.decode!(body) == %{
"type" => "m.login.password",
Expand Down Expand Up @@ -95,8 +101,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}}
end)
|> expect(:get!, fn url ->
|> expect(:get!, fn url, headers, options ->
assert url == "https://example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

%HTTPoison.Response{
status_code: 404,
Expand Down Expand Up @@ -134,8 +142,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}}
end)
|> expect(:get!, fn url ->
|> expect(:get!, fn url, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

%HTTPoison.Response{
status_code: 200,
Expand All @@ -150,8 +160,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}
end)
|> expect(:post!, fn url, body ->
|> expect(:post!, fn url, body, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

assert Jason.decode!(body) == %{
"type" => "m.login.password",
Expand Down Expand Up @@ -213,8 +225,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}}
end)
|> expect(:get!, fn url ->
|> expect(:get!, fn url, headers, options ->
assert url == "https://matrix.example.com/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

%HTTPoison.Response{
status_code: 200,
Expand All @@ -232,8 +246,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}
end)
|> expect(:post!, fn url, body ->
|> expect(:post!, fn url, body, headers, options ->
assert url == "https://matrix.example.com/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

assert Jason.decode!(body) == %{
"type" => "m.login.password",
Expand Down Expand Up @@ -293,8 +309,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}}
end)
|> expect(:get!, fn url ->
|> expect(:get!, fn url, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

%HTTPoison.Response{
status_code: 200,
Expand Down Expand Up @@ -338,8 +356,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}}
end)
|> expect(:get!, fn url ->
|> expect(:get!, fn url, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

%HTTPoison.Response{
status_code: 200,
Expand All @@ -354,8 +374,10 @@ defmodule M51.MatrixClient.ClientTest do
"""
}
end)
|> expect(:post!, fn url, body ->
|> expect(:post!, fn url, body, headers, options ->
assert url == "https://matrix.example.org/_matrix/client/r0/login"
assert headers == []
assert options == [timeout: @timeout]

assert Jason.decode!(body) == %{
"type" => "m.login.password",
Expand Down

0 comments on commit 8cf8f99

Please sign in to comment.