You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku测试夜间突发失败:无法配置SQL Sandbox

Fixing the SQL Sandbox Pool Configuration Error on Heroku

Hey there, let's work through this issue you're hitting on Heroku with your Elixir tests—especially since it ran fine Friday and works perfectly locally.

First, let's unpack the error you're seeing:

** (RuntimeError) cannot configure sandbox with pool DBConnection.Poolboy. To use the SQL Sandbox, configure your repository pool as: pool: Ecto.Adapters.SQL.Sandbox

This error boils down to a config mismatch: your Ecto Repository is using the DBConnection.Poolboy pool (standard for production) when it should be using Ecto.Adapters.SQL.Sandbox for testing. The SQL Sandbox relies on its own pool setup to handle test isolation, so mixing these two causes a conflict.

Why this happens on Heroku (but not locally)

Looking at your logs, this line stands out:

08:29:53.389 [info] seeding in prod environment

When you run mix test locally, it automatically uses the test environment (pulling config from config/test.exs). But on Heroku, your test command is running in the prod environment instead—where your repo is configured to use Poolboy. That's why you're seeing this error now, even though everything worked before.

Step-by-step fixes

  1. Confirm your test environment config
    Open config/test.exs and make sure your repository explicitly uses the Sandbox pool:

    config :your_app, YourApp.Repo,
      pool: Ecto.Adapters.SQL.Sandbox,
      # ... other test-specific settings (database name, credentials, etc.)
    

    Your config/prod.exs should still use Poolboy—this is correct for production, just not for tests.

  2. Force the test environment when running tests on Heroku
    Instead of running just mix test, explicitly set the environment to test with this command:

    MIX_ENV=test mix test
    

    If you're using a Heroku pipeline or a predefined test script, update it to include MIX_ENV=test to ensure tests always use the right config.

  3. Check Heroku's global environment variables
    Double-check that you haven't set MIX_ENV=prod globally for your Heroku app (which would override the test environment even during test runs). You can verify this with:

    heroku config:get MIX_ENV --app your-app-name
    

    If it returns prod, no need to change this globally—just make sure your test command overrides it with MIX_ENV=test.

Quick recap

The root problem is that Heroku is running your tests in the production environment (using Poolboy) instead of the test environment (which should use the Sandbox). By forcing the test environment and confirming your configs are set properly, you should get past this error.

内容的提问来源于stack exchange,提问作者Jack Carlisle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:27:07