Skip to content

Commit 2994d65

Browse files
authored
fix: Repo.Replica returns main Repo if master region (#1653)
1 parent 5eca638 commit 2994d65

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/realtime/repo_replica.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ defmodule Realtime.Repo.Replica do
4545
end
4646

4747
region = Application.get_env(:realtime, :region)
48+
master_region = Application.get_env(:realtime, :master_region) || region
4849
replica = Map.get(replicas, region)
4950
replica_conf = Application.get_env(:realtime, replica)
5051

@@ -56,6 +57,9 @@ defmodule Realtime.Repo.Replica do
5657
is_nil(replica_conf) ->
5758
Realtime.Repo
5859

60+
region == master_region ->
61+
Realtime.Repo
62+
5963
true ->
6064
# Check if module is present
6165
case Code.ensure_compiled(replica) do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
44
def project do
55
[
66
app: :realtime,
7-
version: "2.67.5",
7+
version: "2.67.6",
88
elixir: "~> 1.18",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
start_permanent: Mix.env() == :prod,

test/realtime/repo_replica_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,33 @@ defmodule Realtime.Repo.ReplicaTest do
66
setup do
77
previous_platform = Application.get_env(:realtime, :platform)
88
previous_region = Application.get_env(:realtime, :region)
9+
previous_master_region = Application.get_env(:realtime, :master_region)
910

1011
on_exit(fn ->
1112
Application.put_env(:realtime, :platform, previous_platform)
1213
Application.put_env(:realtime, :region, previous_region)
14+
Application.put_env(:realtime, :master_region, previous_master_region)
1315
end)
1416
end
1517

1618
describe "handle aws platform" do
1719
for {region, mod} <- Replica.replicas_aws() do
1820
setup do
1921
Application.put_env(:realtime, :platform, :aws)
22+
Application.put_env(:realtime, :master_region, "special-region")
23+
:ok
2024
end
2125

2226
test "handles #{region} region" do
2327
Application.put_env(:realtime, :region, unquote(region))
2428
replica_asserts(unquote(mod), Replica.replica())
2529
end
30+
31+
test "defaults to Realtime.Repo if region is equal to master region on #{region}" do
32+
Application.put_env(:realtime, :region, unquote(region))
33+
Application.put_env(:realtime, :master_region, unquote(region))
34+
replica_asserts(Realtime.Repo, Replica.replica())
35+
end
2636
end
2737

2838
test "defaults to Realtime.Repo if region is not configured" do
@@ -35,6 +45,8 @@ defmodule Realtime.Repo.ReplicaTest do
3545
for {region, mod} <- Replica.replicas_fly() do
3646
setup do
3747
Application.put_env(:realtime, :platform, :fly)
48+
Application.put_env(:realtime, :master_region, "special-region")
49+
:ok
3850
end
3951

4052
test "handles #{region} region" do

0 commit comments

Comments
 (0)