Skip to content

Commit

Permalink
Test schema usage applies to shared database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
slashdotdash committed Oct 18, 2020
1 parent 84fa2c4 commit d7bd0c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ defmodule EventStore do
This can be done in config:
# config/config.exs
config :my_app, EventStore, shared_connection_pool: :shared_pool
config :my_app, MyApp.EventStore, shared_connection_pool: :shared_pool
Or when starting the event stores, such as via a `Supervisor`:
Expand Down
24 changes: 20 additions & 4 deletions test/shared_connection_pool_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,34 @@ defmodule EventStore.SharedConnectionPoolTest do

alias EventStore.EventFactory
alias EventStore.MonitoredServer.State, as: MonitoredServerState
alias EventStore.Tasks.{Create, Drop, Init}

describe "connection pool sharing" do
setup do
for schema <- ["schema1", "schema2"] do
config = TestEventStore.config() |> Keyword.put(:schema, schema)

Create.exec(config, quiet: true)
Init.exec(TestEventStore, config, quiet: true)
end

start_supervised!(
{TestEventStore, name: :eventstore1, shared_connection_pool: :shared_pool}
{TestEventStore,
name: :eventstore1, shared_connection_pool: :shared_pool, schema: "schema1"}
)

start_supervised!(
{TestEventStore, name: :eventstore2, shared_connection_pool: :shared_pool}
{TestEventStore,
name: :eventstore2, shared_connection_pool: :shared_pool, schema: "schema2"}
)

:ok
on_exit(fn ->
for schema <- ["schema1", "schema2"] do
config = TestEventStore.config() |> Keyword.put(:schema, schema)

Drop.exec(config, quiet: true)
end
end)
end

test "should only start one Postgrex connection pool" do
Expand Down Expand Up @@ -45,7 +61,7 @@ defmodule EventStore.SharedConnectionPoolTest do
{:ok, events} = append_events_to_stream(:eventstore1, stream_uuid, 3)

assert_recorded_events(:eventstore1, stream_uuid, events)
assert_recorded_events(:eventstore2, stream_uuid, events)
assert_recorded_events(:eventstore2, stream_uuid, [])
end
end

Expand Down

0 comments on commit d7bd0c9

Please sign in to comment.