简体   繁体   English

在容器化的Elixir 1.6.1中运行phoenix测试的数据库所有权过程错误

[英]DB Ownership process error running phoenix test in containerized elixir 1.6.1

I have an umbrella project compose by: 我有一个伞项目由以下人员撰写:

  • gateway - Phoenix application 网关-Phoenix应用程序
  • core - business model layer notifications a dedicated app for delivering sms, email, etc… users 核心-业务模型层通知专用的应用程序,用于发送短信,电子邮件等…用户
  • user management, role system, and authentication. 用户管理,角色系统和身份验证。

The three components are connected via AMQP, so they can send and receive messages between them. 这三个组件通过AMQP连接,因此它们可以在它们之间发送和接收消息。

We are using Docker, and drone.io hosted on google cloud's kubernetes engine. 我们正在使用Docker,并且drone.io托管在Google Cloud的kubernetes引擎上。 So, what is happening is that randomly the application raises the following exception while running my tests: 因此,正在发生的是,在运行我的测试时,应用程序随机引发以下异常:

{\"status\":\"error\",\"message\":\"%DBConnection.OwnershipError{message: \\\"cannot find ownership process for #PID<0.716.0>.\\\\n\\\\nWhen using ownership, you must manage connections in one\\\\nof the four ways:\\\\n\\\\n* By explicitly checking out a connection\\\\n* By explicitly allowing a spawned process\\\\n* By running the pool in shared mode\\\\n* By using :caller option with allowed process\\\\n\\\\nThe first two options require every new process to explicitly\\\\ncheck a connection out or be allowed by calling checkout or\\\\nallow respectively.\\\\n\\\\nThe third option requires a {:shared, pid} mode to be set.\\\\nIf using shared mode in tests, make sure your tests are not\\\\nasync.\\\\n\\\\nThe fourth option requires [caller: pid] to be used when\\\\nchecking out a connection from the pool. The caller process\\\\nshould already be allowed on a connection.\\\\n\\\\nIf you are reading this error, it means you have not done one\\\\nof the steps above or that the owner process has crashed.\\\\n\\\\nSee Ecto.Adapters.SQL.Sandbox docs for more information.\\\"}\",\"code\":0}"

It's a Json since we exchange amqp messages in our tests, for instance: 这是一个Json,因为我们在测试中交换了amqp消息,例如:

# Given the module FindUserByEmail
def Users.Services.FindUserByEmail do  
    use GenAMQP.Server, event: "find_user_by_email", conn_name: 
        Application.get_env(:gen_amqp, :conn_name)

    alias User.Repo
    alias User.Models.User, as: UserModel

    def execute(payload) do
      %{ "email" => email } = Poison.decode!(payload)

      resp =
          case Repo.get_by(UserModel, email: email) do
              %UserModel{} = user -> %{status: :ok, response: user}
              nil -> ErrorHelper.err(2011)
              true -> ErrorHelper.err(2012)
              {:error, %Ecto.Changeset{} = changeset} -> ViewHelper.translate_errors(changeset)
          end

      {:reply, Poison.encode!(resp)}
  end
end

# and the test
defmodule Users.Services.FindUserByEmailTest do
  use User.ModelCase
  alias GenAMQP.Client

  def execute(payload) do
      resp = Client.call_with_conn(@conn_name, "find_user_by_email", payload)
      data = Poison.decode!(resp, keys: :atoms)

      assert data.status == "ok"
  end
end

Following details my .drone.yaml file: 以下详细说明了我的.drone.yaml文件:

pipeline:
unit-tests:
image: bitwalker/alpine-elixir-phoenix:1.6.1
environment:
    RABBITCONN: amqp://user:pass@localhost:0000/unit_testing
    DATABASE_URL: ecto://username:password@postgres/testing
commands:
    - mix local.hex --force && mix local.rebar --force
    - mix deps.get
    - mix compile --force
    - mix test

mix.exs file in every app contains the following aliases 每个应用程序中的mix.exs文件都包含以下别名

defp aliases do
    [
        "test": ["ecto.create", "ecto.migrate", "test"]
    ]
end

All ours model_case files contain this configuration: 我们所有的model_case文件都包含以下配置:

setup tags do
    :ok = Sandbox.checkout(User.Repo)

    unless tags[:async] do
        Sandbox.mode(User.Repo, {:shared, self()})
    end

    :ok
end

How can I debug this? 我该如何调试? it only occurs while testing code inside the container. 它仅在测试容器内部的代码时发生。 Would the issue be related to container's resources? 这个问题与集装箱的资源有关吗?

Any tip or hint would be appreciated. 任何提示或提示,将不胜感激。

Try setting onwership_timeout and timeout to a large numbers in your config/tests.exs 尝试在config/tests.exs onwership_timeouttimeout设置为大量

config :app_name, User.Repo,
adapter: Ecto.Adapters.Postgres,
  username: ...,
  password: ...,
  database: ...,
  hostname: ...,
  pool: Ecto.Adapters.SQL.Sandbox,
  timeout: 120_000, # i think the default is 5000
  pool_timeout: 120_000,
  ownership_timeout: 120_000 #i think the default is 5000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM