私はフェニックスアプリケーションに取り組んでいます。このアプリケーションは、アンブレラ アプリの一部です。この傘には、アプリケーションのさまざまな領域を担当する小さなアプリケーションがあります。
- フェニックス Web API (「API」)
- コア ビジネス ロジック (「コア」)
- ユーザー認証 (「auth」)
- データベース スキーマ (「db」)
「api」は「core」と「auth」の両方に依存しますが、これら 2 つのアプリケーションは「db」に依存します。
「db」アプリだけが ecto リポジトリを持ち、他のすべてのアプリにはありません。リポジトリは「db」アプリによって開始され、監視されます。
ここで、「api」アプリケーションでコントローラーをテストしたいと思います。ここでectoの問題に遭遇します。コントローラーアクションをテストすると、このアクションは「auth」または「core」から関数を呼び出し、Repo
「db」からの関数を呼び出します( などRepo.insert/2
)。これにより、OwnershipError
次のようになります。
** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.458.0>.
When using ownership, you must manage connections in one
of the three ways:
* By explicitly checking out a connection
* By explicitly allowing a spawned process
* By running the pool in shared mode
The first two options require every new process to explicitly
check a connection out or be allowed by calling checkout or
allow respectively.
The third option requires a {:shared, pid} mode to be set.
If using shared mode in tests, make sure your tests are not
async.
If you are reading this error, it means you have not done one
of the steps above or that the owner process has crashed.
See Ecto.Adapters.SQL.Sandbox docs for more information.
私の問題は、「api」アプリケーションが「db」アプリケーションを認識していないため、接続チェックアウトを実行できないため、「api」テストで提案された解決策を使用してこのエラーを修正する方法がわからないことです。「db」プロジェクトに直接依存するアプリケーションでこのエラーが発生したとき、「共有モード」ソリューションを適用できました。
私の質問は、「api」統合テストで所有権の問題をどのように解決できるかということです。