Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions lib/snowflex/transport/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Snowflex.Transport.Http do
* `:retry_max_delay` - Maximum delay between retries in milliseconds (default: 8000)
* `:connect_options` - Connection options for Finch pool configuration
* `:req_options` - Additional options to pass to `Req.new/1` (e.g., `:plug` for testing)
* `:fullsweep_after` - Sets the `fullsweep_after` garbage collection flag on the process (default: ERTS default)

## Account Name Handling

Expand Down Expand Up @@ -262,6 +263,10 @@ defmodule Snowflex.Transport.Http do

@impl GenServer
def init(opts) do
if fullsweep_after = Keyword.get(opts, :fullsweep_after) do
:erlang.process_flag(:fullsweep_after, fullsweep_after)
end

with {:ok, validated_opts, private_key} <- validate_and_read_private_key(opts),
{:ok, state} <- init_state(validated_opts, private_key) do
check_connection(state)
Expand Down
39 changes: 39 additions & 0 deletions test/transport/http_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,45 @@ defmodule Snowflex.Transport.HttpTest do
assert %{} = Http.execute_statement(pid, nil, nil, timeout: 1000)
end

describe "fullsweep_after option" do
setup do
Req.Test.set_req_test_to_shared(%{})

Req.Test.stub(Snowflex.Transport.HttpTest.FullsweepPlug, fn conn ->
Req.Test.json(conn, %{})
end)

:ok
end

@fullsweep_opts [
account_name: "test-account",
username: "test_user",
public_key_fingerprint: "test_fingerprint",
private_key_path: Path.join(File.cwd!(), "test/fixtures/fake_private_key.pem"),
req_options: [plug: {Req.Test, Snowflex.Transport.HttpTest.FullsweepPlug}]
]

test "sets process flag when fullsweep_after is provided" do
opts = @fullsweep_opts ++ [fullsweep_after: 0]
{:ok, pid} = Http.start_link(opts)

{:garbage_collection, gc_info} = :erlang.process_info(pid, :garbage_collection)
assert gc_info[:fullsweep_after] == 0

GenServer.stop(pid)
end

test "leaves default when fullsweep_after is not provided" do
{:ok, pid} = Http.start_link(@fullsweep_opts)

{:garbage_collection, gc_info} = :erlang.process_info(pid, :garbage_collection)
assert gc_info[:fullsweep_after] > 0

GenServer.stop(pid)
end
end

describe "private key configuration" do
# Sample private key for testing (this is a dummy key generated for testing only)
@test_private_key """
Expand Down
Loading