ZabGo

ZabGo

Issue when running tests: (Mix.Error) The database for Copi.Repo couldn't be created: killed

Hello,

I’m new to Elixir development. I’ve started to contribute to a website written with the Phoenix framework.

When I run the command mix test, most of the tests are failing. I suspect it’s because my test environment is not set up properly. Indeed, when I run an individual test I’ve got the following error message:

Mix task exited with reason
an exception was raised:
    ** (Mix.Error) The database for Copi.Repo couldn't be created: killed
        (mix 1.16.0) lib/mix.ex:580: Mix.raise/2
        (elixir 1.16.0) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
        (mix 1.16.0) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
        (mix 1.16.0) lib/mix/task.ex:544: Mix.Task.run_alias/6
        (debug_adapter 0.20.0) lib/debug_adapter/server.ex:1969: ElixirLS.DebugAdapter.Server.launch_task/1
returning code 1
11:15:00.361 [error] Process #PID<0.491.0> raised an exception
** (Mix.Error) The database for Copi.Repo couldn't be created: killed
    (mix 1.16.0) lib/mix.ex:580: Mix.raise/2
    (elixir 1.16.0) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
    (mix 1.16.0) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.16.0) lib/mix/task.ex:544: Mix.Task.run_alias/6
    (debug_adapter 0.20.0) lib/debug_adapter/server.ex:1969: ElixirLS.DebugAdapter.Server.launch_task/1

The dev environment is working fine. I can launch the website and add data to the database.

Do I miss something to set up the test environment?

Thank you for you help. :slight_smile:

First 6 of 6 Posts Switch mode

emadb

emadb

Seems like that the tests cannot reach the database. Is it running? The connection url for test env is correct?

If it works in dev mode you can try run the application in test env:

MIX_ENV=test iex -S mix

Doing so could help in finding the problem.

dimitarvp

dimitarvp

Can you show us the aliases section of your mix.exs file? Also sometimes this happens when people have fallible code in their application initialization.

Look for <YOUR_APP>.Application module and its init function.

ZabGo

ZabGo OP

Hello both,

Thank you very much for taking the time to answer my question. I actually managed to “solve the problem”. At least I can run the tests individually. The reason for that is that I extracted the user and password of the database to another file as below:

username: System.get_env("POSTGRES_USER"),
password: System.get_env("POSTGRES_PASSWORD"),

When I changed back to a hardcoded value as below I works fine

username: "my_user",
password: "my_password",
arcanemachine

arcanemachine

One solution I’ve experienced is to make sure you’re exporting your environment variables.

For example, this might not work:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

mix test

But this might:

export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres

mix test
ZabGo

ZabGo OP

Thanks @arcanemachine for you reply. mix test is working fine as I source the file where I keep my environment variable before running mix test. The issue is when I run one test on its own from VSCode using the VSCode debugger. I actually wonder if it’s creating a subshell to run this test?

arcanemachine

arcanemachine

Yeah, sounds like a VS Code problem. Could also depend on how you’re setting the environment variables too.

I can’t help with the VS Code stuff… but to prevent suprises like this in the future, you could use System.fetch_env!/1 so that the system raises an exception if you haven’t actually set the environment variable. It’s nice when you know 100% that the env var will be set somewhere.

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement