Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Attempt to fix some flaky Elixir unit tests #4927

Closed
wants to merge 4 commits into from
Closed
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
39 changes: 31 additions & 8 deletions elixir/apps/domain/test/support/mocks/openid_connect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defmodule Domain.Mocks.OpenIDConnect do

Bypass.stub(bypass, "GET", "/.well-known/openid-configuration", fn conn ->
conn = fetch_conn_params(conn)
send(test_pid, {:request, conn})

attrs = %{
"issuer" => "#{endpoint}/",
Expand Down Expand Up @@ -91,7 +90,13 @@ defmodule Domain.Mocks.OpenIDConnect do
"request_parameter_supported" => false
}

Plug.Conn.resp(conn, 200, Jason.encode!(attrs))
# Process may not be alive in slow CI environments
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Process.alive?(test_pid) do
send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 200, Jason.encode!(attrs))
else
Plug.Conn.resp(conn, 503, "")
end
end)

bypass
Expand All @@ -102,8 +107,14 @@ defmodule Domain.Mocks.OpenIDConnect do

Bypass.expect(bypass, "POST", "/oauth/token", fn conn ->
conn = fetch_conn_params(conn)
send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 200, Jason.encode!(attrs))

# Process may not be alive in slow CI environments
if Process.alive?(test_pid) do
send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 200, Jason.encode!(attrs))
else
Plug.Conn.resp(conn, 503, "")
end
end)

bypass
Expand All @@ -114,8 +125,14 @@ defmodule Domain.Mocks.OpenIDConnect do

Bypass.expect(bypass, "POST", "/oauth/token", fn conn ->
conn = fetch_conn_params(conn)
send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 401, Jason.encode!(attrs))

# Process may not be alive in slow CI environments
if Process.alive?(test_pid) do
send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 401, Jason.encode!(attrs))
else
Plug.Conn.resp(conn, 503, "")
end
end)

bypass
Expand All @@ -142,8 +159,14 @@ defmodule Domain.Mocks.OpenIDConnect do
)

conn = fetch_conn_params(conn)
send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 200, Jason.encode!(attrs))

# Process may not be alive in slow CI environments
if Process.alive?(test_pid) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix anything, the issue happens when Plug process is trying to read from Bypass process. So when the Plug process is terminated with the test process, the bypass can't finish reading the full response. And it doesn't matter if the response code is 503 or 401, has body or not, etc.

send(test_pid, {:request, conn})
Plug.Conn.resp(conn, 200, Jason.encode!(attrs))
else
Plug.Conn.resp(conn, 503, "")
end
end)

bypass
Expand Down
3 changes: 2 additions & 1 deletion elixir/apps/web/test/support/acceptance_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ defmodule Web.AcceptanceCase do
if env = System.get_env("E2E_DEFAULT_WAIT_SECONDS") do
String.to_integer(env)
else
2
# GitHub shared runners can be very slow during peak hours
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamilbk it's already 5 seconds on CI: E2E_DEFAULT_WAIT_SECONDS in

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

5
end
end

Expand Down
Loading