Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abc3 committed Oct 18, 2023
1 parent 3cba0b0 commit 67b10b6
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.15
0.9.16
9 changes: 8 additions & 1 deletion lib/supavisor/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ defmodule Supavisor.Application do
child_spec: DynamicSupervisor, strategy: :one_for_one, name: Supavisor.DynamicSupervisor
},
Supavisor.Vault,
{Cachex, name: Supavisor.Cache},
Supavisor.TenantsMetrics,
# Start the Endpoint (http/https)
SupavisorWeb.Endpoint
]

# start Cachex only if the node uses names, this is necessary for test setup
children =
if node() != :nonode@nohost do
[{Cachex, name: Supavisor.Cache} | children]
else
children
end

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Supavisor.Supervisor]
Expand Down
2 changes: 1 addition & 1 deletion lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ defmodule Supavisor.ClientHandler do
:keep_state_and_data

{:buffering, size} ->
Logger.warn("DB call buffering #{size}}")
Logger.debug("DB call buffering #{size}")

if size > 1_000_000 do
msg = "Db buffer size is too big: #{size}"
Expand Down
18 changes: 5 additions & 13 deletions lib/supavisor/handler_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ defmodule Supavisor.HandlerHelpers do
@spec ssl_recv(S.tcp_sock()) :: {:ok, S.ssl_sock()} | {:error, term}
def ssl_recv({:gen_tcp, sock} = s) do
case :gen_tcp.recv(sock, 1, 15_000) do
{:ok, <<?S>>} ->
ssl_connect(s)

{:ok, <<?N>>} ->
{:ok, s}

{:error, _} = error ->
error
{:ok, <<?S>>} -> ssl_connect(s)
{:ok, <<?N>>} -> {:ok, s}
{:error, _} = error -> error
end
end

Expand All @@ -55,11 +50,8 @@ defmodule Supavisor.HandlerHelpers do
opts = [verify: :verify_none]

case :ssl.connect(sock, opts, timeout) do
{:ok, ssl_sock} ->
{:ok, {:ssl, ssl_sock}}

{:error, reason} ->
{:error, reason}
{:ok, ssl_sock} -> {:ok, {:ssl, ssl_sock}}
{:error, reason} -> {:error, reason}
end
end

Expand Down
15 changes: 8 additions & 7 deletions lib/supavisor/monitoring/prom_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ defmodule Supavisor.Monitoring.PromEx do
Registry.select(Supavisor.Registry.TenantClients, [{{:"$1", :_, :_}, [], [:"$1"]}])
|> Enum.uniq()

Enum.reduce(pools, metrics, fn {tenant, _, _}, acc ->
{matched, rest} = Enum.split_with(acc, &String.contains?(&1, "tenant=\"#{tenant}\""))
_ =
Enum.reduce(pools, metrics, fn {tenant, _, _}, acc ->
{matched, rest} = Enum.split_with(acc, &String.contains?(&1, "tenant=\"#{tenant}\""))

if matched != [] do
Cachex.put(Supavisor.Cache, {:metrics, tenant}, Enum.join(matched, "\n"))
end
if matched != [] do
Cachex.put(Supavisor.Cache, {:metrics, tenant}, Enum.join(matched, "\n"))
end

rest
end)
rest
end)

pools
end
Expand Down
6 changes: 3 additions & 3 deletions lib/supavisor_web/open_api_schemas.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule SupavisorWeb.OpenApiSchemas do
db_password: "postgres",
pool_size: 10,
is_manager: false,
max_clients: 25000,
max_clients: 25_000,
mode_type: "transaction",
inserted_at: "2023-03-27T12:00:00Z",
updated_at: "2023-03-27T12:00:00Z"
Expand Down Expand Up @@ -101,7 +101,7 @@ defmodule SupavisorWeb.OpenApiSchemas do
db_user: "postgres",
db_password: "postgres",
pool_size: 10,
max_clients: 25000,
max_clients: 25_000,
pool_checkout_timeout: 1000,
is_manager: false,
mode_type: "transaction",
Expand Down Expand Up @@ -172,7 +172,7 @@ defmodule SupavisorWeb.OpenApiSchemas do
db_password: "postgres",
pool_size: 10,
mode_type: "transaction",
max_clients: 25000,
max_clients: 25_000,
pool_checkout_timeout: 1000
}
]
Expand Down
10 changes: 5 additions & 5 deletions test/supavisor/client_handler_test.exs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
defmodule Supavisor.ClientHandlerTest do
use ExUnit.Case, async: true

alias Supavisor.ClientHandler
alias Supavisor.HandlerHelpers, as: HH

describe "parse_user_info/1" do
test "extracts the external_id from the username" do
payload = %{"user" => "test.user.external_id"}
{name, external_id} = ClientHandler.parse_user_info(payload)
{name, external_id} = HH.parse_user_info(payload)
assert name == "test.user"
assert external_id == "external_id"
end

test "username consists only of username" do
username = "username"
payload = %{"user" => username}
{user, nil} = ClientHandler.parse_user_info(payload)
{user, nil} = HH.parse_user_info(payload)
assert username == user
end

test "external_id in options" do
user = "test.user"
external_id = "external_id"
payload = %{"options" => %{"reference" => external_id}, "user" => user}
{user1, external_id1} = ClientHandler.parse_user_info(payload)
{user1, external_id1} = HH.parse_user_info(payload)
assert user1 == user
assert external_id1 == external_id
end

test "unicode in username" do
payload = %{"user" => "тестовe.імʼя.external_id"}
{name, external_id} = ClientHandler.parse_user_info(payload)
{name, external_id} = HH.parse_user_info(payload)
assert name == "тестовe.імʼя"
assert external_id == "external_id"
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ Supavisor.Support.Cluster.apply_config(node2)

{:ok, _} = :erpc.call(node2, :application, :ensure_all_started, [:supavisor])

Cachex.start_link(name: Supavisor.Cache)

ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Supavisor.Repo, :auto)

0 comments on commit 67b10b6

Please sign in to comment.