[error] Postgrex.Protocol (#PID<0.XXX.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.XXX.0> exited while client #PID<0.XXX.0> is still running with: shutdown
现在我想我了解发生了什么:在db事务完成之前,正在检查Ecto SandBox连接池.根据文档(至少我读它们的方式),解决这些问题的方法是使用共享连接池:Ecto.Adapters.sql.SandBox.mode(MyApp.Repo,{:shared,self()} )我在做什么.不幸的是,这不起作用.@H_403_5@
解决方法
Yes,your understanding of the issue is correct. It is happening because the test process,the one who owns the connection,has exited but the Task is still using its connection. Using {:shared,self()} does not fix it because the test is still owning the connection,you are just sharing it implicitly.@H_403_5@
The way to fix is to guarantee the Task has finished before the test exits. This can be done by calling Process.exit(task_pid,:kill). If you don’t know the Task PID,you can call Task.Supervisor.which_children(NameOfYourTaskSupervisor) to return all PIDs which you then traverse and kill them. However,if you do this approach,the test cannot run concurrently (as you may kill tasks started by another test).@H_403_5@