From d7bd0c9e5742cec79156d15d9e4e011e3dd35d1d Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Sun, 18 Oct 2020 20:25:59 +0100 Subject: [PATCH] Test schema usage applies to shared database connection --- lib/event_store.ex | 2 +- test/shared_connection_pool_test.exs | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/event_store.ex b/lib/event_store.ex index 91bdaa6a..7f778609 100644 --- a/lib/event_store.ex +++ b/lib/event_store.ex @@ -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`: diff --git a/test/shared_connection_pool_test.exs b/test/shared_connection_pool_test.exs index 7694117d..134afaf1 100644 --- a/test/shared_connection_pool_test.exs +++ b/test/shared_connection_pool_test.exs @@ -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 @@ -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