LionelMarco

LionelMarco

Phoenix how to disabled Ecto sanbox in test- Test without sandbox

In previous Phoenix version I have been running test in my database without any sandbox and everyting run well.
Because already we have a specific database for development,configured in: config/test.exs
Now upgrade Phoenix and a new feature appear Sandbox

So I want to make all changes insert, update, delete, persistent.

I read this post but it is not was usefull for me:

I don’t want to use Shared mode:

I just only want to remove the sanbox an work in the database

Please can somebody tell me wich is the right way.

This is a part from my test.exs:

import Config

config :gis, Gis.Repo,
  username: "gisuser",
  password: "gisuser",
  hostname: "localhost",
  database: "gisapp" , #{System.get_env("MIX_TEST_PARTITION")}",
  pool: Ecto.Adapters.SQL.Sandbox,
  pool_size: 10

How to configure pool argument to use NO sandbox ?
What must to write to directly use my Repo
Or may be need to change : connn_case.ex file

I try removing the next line from test_helpers.exs


# Ecto.Adapters.SQL.Sandbox.mode(Gis.Repo, :manual)

and remove:

#pool: Ecto.Adapters.SQL.Sandbox,
from config/test.exs

But nothing happen

Also the documentation does not say anything of how to disable it.

please can anybody tell me how to proceed ?

Greetings

Marked As Solved

dimitarvp

dimitarvp

I am probably not understanding you well here but what exactly is stopping you from having several DB dumps that you can restore on top of each other? And then when you want to test a certain scenario that needs database dump 1, 4 and 6, you just make a mix task alias to clear up the test DB and then load those dumps in order?

I’ve done that too, several times in my career. There’s really no point in running expensive seeding scripts if the required test data barely changes; so just make one functional and good copy of the DB and pg_dump it and then pg_restore it before tests.

Also Liked

dimitarvp

dimitarvp

Are you really really sure you want that? You can just as well just seed / populate your test DB to have baseline data that you need – that’s a legitimate need, a good amount of applications cannot run adequate tests on an empty DB – and then proceed to run tests in the normal sandboxed manner.

nathanl

nathanl

The way the sandbox works is:

  1. start a database transaction at the start of the test
  2. data gets inserted and updated in the database and read from the database within that transaction during the test
  3. at the end of the test, roll back the transaction instead of committing it

Since transaction COMMIT never happens, the data is never really persisted in the database. So I don’t think pg_dump would have any access to it.

dli

dli

Late to the party, but you can do Ecto.Adapters.SQL.Sandbox.start_owner!(Repo, sandbox: false) in your DataCase setup. This prevents wrapping each test in a transaction that is rolled back at the end of the test.

Some options like sandbox are passed to Ecto.Adapters.SQL.Sandbox.checkout/2. The behaviour is documented there.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement