@@ -19,7 +19,7 @@ defmodule Ecto.Integration.SandboxTest do
1919 Sandbox . mode ( UnknownRepo , :manual )
2020 end
2121 end
22-
22+
2323 test "raises if repo is not started" do
2424 assert_raise RuntimeError , ~r" could not lookup Ecto repo #{ inspect DynamicRepo } because it was not started" , fn ->
2525 Sandbox . mode ( DynamicRepo , :manual )
@@ -75,6 +75,27 @@ defmodule Ecto.Integration.SandboxTest do
7575 assert TestRepo . all ( Post ) == [ ]
7676 end
7777
78+ test "uses the repository when allowed from another process by registered name" do
79+ assert_raise DBConnection.OwnershipError , ~r" cannot find ownership process" , fn ->
80+ TestRepo . all ( Post )
81+ end
82+
83+ parent = self ( )
84+ Process . register ( parent , __MODULE__ )
85+
86+ Task . start_link fn ->
87+ Sandbox . checkout ( TestRepo )
88+ Sandbox . allow ( TestRepo , self ( ) , __MODULE__ )
89+ send ( parent , :allowed )
90+ Process . sleep ( :infinity )
91+ end
92+
93+ assert_receive :allowed
94+ assert TestRepo . all ( Post ) == [ ]
95+
96+ Process . unregister ( __MODULE__ )
97+ end
98+
7899 test "uses the repository when shared from another process" do
79100 assert_raise DBConnection.OwnershipError , ~r" cannot find ownership process" , fn ->
80101 TestRepo . all ( Post )
@@ -94,17 +115,17 @@ defmodule Ecto.Integration.SandboxTest do
94115 after
95116 Sandbox . mode ( TestRepo , :manual )
96117 end
97-
118+
98119 test "works with a dynamic repo" do
99120 repo_pid = start_supervised! ( { DynamicRepo , name: nil } )
100121 DynamicRepo . put_dynamic_repo ( repo_pid )
101-
122+
102123 assert Sandbox . mode ( DynamicRepo , :manual ) == :ok
103-
124+
104125 assert_raise DBConnection.OwnershipError , ~r" cannot find ownership process" , fn ->
105126 DynamicRepo . all ( Post )
106127 end
107-
128+
108129 Sandbox . checkout ( DynamicRepo )
109130 assert DynamicRepo . all ( Post ) == [ ]
110131 end
0 commit comments