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

fix: merge session mode pool config with main config, preserving options #293

Merged
merged 2 commits into from
Dec 18, 2024
Merged
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
3 changes: 2 additions & 1 deletion lib/event_store/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ defmodule EventStore.Config do
# connections (advisory locks and notifications). Uses the default Postgres
# configuration if not specified.
defp session_mode_pool_config(config) do
Keyword.get(config, :session_mode_pool, config)
config
|> Keyword.merge(Keyword.get(config, :session_mode_pool, []))
end
end
32 changes: 32 additions & 0 deletions test/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,38 @@ defmodule EventStore.ConfigTest do
)
end

test "passes parent config options to session mode pool config" do
config = [
ssl: true,
ssl_opts: [cacertfile: ~c"/etc/ssl/certs/db.ca-certificate.crt", verify: :verify_peer],
prepare: :unnamed,
session_mode_url: "postgres://username:password@localhost/database"
]

session_mode_pool_config =
Config.parse(config) |> Config.postgrex_notifications_opts(:name) |> Enum.sort()

assert session_mode_pool_config == [
auto_reconnect: true,
backoff_type: :exp,
database: "database",
hostname: "localhost",
name: :name,
password: "password",
pool: DBConnection.ConnectionPool,
pool_size: 1,
prepare: :unnamed,
ssl: true,
ssl_opts: [
cacertfile: ~c"/etc/ssl/certs/db.ca-certificate.crt",
verify: :verify_peer
],
sync_connect: false,
timeout: 15000,
username: "username"
]
end

test "parse url with query parameters" do
config = [
url: "postgres://username:password@localhost/database?ssl=true&pool_size=5&timeout=120000"
Expand Down
Loading