Skip to content

Commit

Permalink
Merge pull request #293 from gf3/fix/session-mode-pool-config
Browse files Browse the repository at this point in the history
fix: merge session mode pool config with main config, preserving options
  • Loading branch information
drteeth authored Dec 18, 2024
2 parents 42399ab + 7853750 commit f88aae6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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

0 comments on commit f88aae6

Please sign in to comment.