LionelMarco

LionelMarco

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

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

@LionelMarco Simply replace the config :gis, Gis.Repo contents with the same stuff you have in dev, but change the database to whatever you want to use for your test db.

However there are some things that are confusing me here:

The Ecto Sandbox is not a Phoenix feature, it’s an ecto feature. It’s also opt in so simply upgrading ecto will not add it to your project. If you were not using it before, how did it end up in your project at all?

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.

LionelMarco

LionelMarco OP

can’t delete this

dimitarvp

dimitarvp

Saw your edit – no need to delete.

If you need different seeds then just make different seed scripts? Easy enough, just put them in priv/repo/seeds/ and then fill up the test DB with MIX_ENV=test mix run priv/repo/seeds/team_one_seeds.exs for example.

LionelMarco

LionelMarco OP

Yes SandBox is a Ecto feature was a misundertanding error.

Copy the code from dev.exs is exactly what I tried:
my test.exs:

config :gis, Gis.Repo,
  username: "gisuser",
  password: "gisuser",
  hostname: "localhost",
  database: "gistest"

If I run: mix test

I get a lot of errors like that:

      1) test renders 404.html (GisWeb.ErrorHTMLTest)
     test/gis_web/controllers/error_html_test.exs:7
     ** (MatchError) no match of right hand side value: {:error, {%RuntimeError{message: "cannot invoke sandbox operation with pool DBConnection.ConnectionPool.\nTo use the SQL Sandbox, configure your repository pool as:\n\n    pool: Ecto.Adapters.SQL.Sandbox\n"}, [{Ecto.Adapters.SQL.Sandbox, :lookup_meta!, 1, [file: ~c"lib/ecto/adapters/sql/sandbox.ex", line: 575, error_info: %{module: Exception}]}, {Ecto.Adapters.SQL.Sandbox, :checkout, 2, [file: ~c"lib/ecto/adapters/sql/sandbox.ex", line: 485]}, {Ecto.Adapters.SQL.Sandbox, :"-start_owner!/2-fun-0-", 3, [file: ~c"lib/ecto/adapters/sql/sandbox.ex", line: 407]}, {Agent.Server, :init, 1, [file: ~c"lib/agent/server.ex", line: 8]}, {:gen_server, :init_it, 2, [file: ~c"gen_server.erl", line: 962]}, {:gen_server, :init_it, 6, [file: ~c"gen_server.erl", line: 917]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 241]}]}}
     stacktrace:

And if I run : mix test ./test/data_layer_test.exs
I get:

** (RuntimeError) cannot invoke sandbox operation with pool DBConnection.ConnectionPool.
To use the SQL Sandbox, configure your repository pool as:

    pool: Ecto.Adapters.SQL.Sandbox

    (ecto_sql 3.10.2) lib/ecto/adapters/sql/sandbox.ex:575: Ecto.Adapters.SQL.Sandbox.lookup_meta!/1
    (ecto_sql 3.10.2) lib/ecto/adapters/sql/sandbox.ex:458: Ecto.Adapters.SQL.Sandbox.mode/2
    test/test_helper.exs:2: (file)

Also there is a file named “test_helpers.exs”

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

I tried commenting the second line but nothing happen.

What should I do with him?

What cant be wrong ??

LostKobrakai

LostKobrakai

Search for all calls on Ecto.Adapters.SQL.Sandbox functions. The one in test_helpers.exs is not the only one. Though like others I’d suggest validating if that’s indeed the best way forward. Manually maintaining db state across tests can easily become a problem.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Again I want to ask how your project got in this state? Upgrading Ecto does not magically introduce the sandbox into your project.

LionelMarco

LionelMarco OP

Ben, my main goal was to update Phoenix to version 1.7. in order to use Core components, it is the only reason, so:

  1. Install it:

mix archive.install hex phx_new 1.7.7

  1. Then run

mix phx.new gisapp

  1. And then this is the mix.exs created:

  defp deps do
    [
      {:phoenix, "~> 1.7.7"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.10"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 3.3"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.19.0"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.8.0"},
      {:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.3"},
      {:finch, "~> 0.13"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.20"},
      {:jason, "~> 1.2"},
      {:plug_cowboy, "~> 2.5"}
    ]
  end

Can you tell me if I can downgrade to a version without sandbox ?


Also there is a file : test/support/data_case.ex
where the sand box is started or configured, is there any way to turn off it,

Why something that should be so easy like:

with_sand_box: false

Is not implemented ?

I am used to work just with Cowboy, and it does not have sandbox in test.

Greetings

dimitarvp

dimitarvp

There is no such version. Also that’s a feature of Ecto, not a feature of Phoenix.

Because having a persistent test DB is a bad practice.

You never answered the questions why do you need this. I’m willing to bet you’ll be better off with the sandbox.

LionelMarco

LionelMarco OP

I do work for a company that distributes gas to homes with more than 2,000,000 homes, there are many areas, measurement, billing, payments, accounting, etc. There is a specific database for development, totally isolated from production. To test each area needs the data from the previous one. And each area tests in due time. In times unrelated to those of the others.
Each test involves thousands of items that are created and stored procedures that must be executed. This takes a lot of time.
This is the working methodology, it may not be the correct one, but it is the one we use.

when configured the database in test.exs Is there any way to set another kind of pool ? that work without transaction ?

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews