diff --git a/lib/snowflex/transport/http.ex b/lib/snowflex/transport/http.ex index e7edd3f..3885f3c 100644 --- a/lib/snowflex/transport/http.ex +++ b/lib/snowflex/transport/http.ex @@ -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 @@ -262,6 +263,11 @@ defmodule Snowflex.Transport.Http do @impl GenServer def init(opts) do + if fullsweep_after = Keyword.get(opts, :fullsweep_after) do + _ = Process.flag(:fullsweep_after, fullsweep_after) + :ok + 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) diff --git a/test/transport/http_test.exs b/test/transport/http_test.exs index 5477760..af500be 100644 --- a/test/transport/http_test.exs +++ b/test/transport/http_test.exs @@ -1,8 +1,10 @@ defmodule Snowflex.Transport.HttpTest do use ExUnit.Case + alias Req.Test, as: ReqTest alias Snowflex.Error alias Snowflex.Transport.Http + alias Snowflex.Transport.HttpTest.FullsweepPlug defmodule DummyHttp do use GenServer @@ -33,6 +35,45 @@ defmodule Snowflex.Transport.HttpTest do assert %{} = Http.execute_statement(pid, nil, nil, timeout: 1000) end + describe "fullsweep_after option" do + setup do + ReqTest.set_req_test_to_shared(%{}) + + ReqTest.stub(FullsweepPlug, fn conn -> + ReqTest.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: {ReqTest, 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} = 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} = 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 """