Sleepful

Sleepful

So I was reading of the multiple modes for Ecto.Adapters.SQL.Sandbox, it seems you have to use only one of the modes for your test suite so you have to pick one of the three options available: :auto (default), :manual or :shared.

Trying to figure out which is the best, so I want to poll opinions :slightly_smiling_face:

Found this related article which explains it a little more Making Sense of Ecto 2 SQL.Sandbox and Connection Ownership Modes

Showing Posts 1 to 4

JohnnyCurran

JohnnyCurran

The links you shared are a little out of date :slight_smile: The updated documentation is at Ecto.Adapters.SQL.Sandbox — Ecto SQL v3.14.0 - Your version is Ecto 2.0 beta. Ecto is now on version 3.9

You probably want to leave it on :auto or set it to :manual - I set it to :manual in test_helpers.exs

If you use :shared, you can no longer run your tests async. This is because :shared mode can introduce non-determinism because the test processes / transactions can see each of the other test transactions data it has inserted into the database. See 8 Common Causes of Flaky Tests in Elixir | AppSignal Blog for more info (#2 in the list)

Sleepful

Sleepful OP

Oh you are right that I linked an older version of ecto. Well it seems like the docs for Ecto.Adapters.SQL.Sandbox have not changed much between versions and it works the same, unless I missed some relevant difference. So the links I shared still remain relevant. Did notice one difference: :auto mode in newer version does not require checkin/1 to return connections to the pool.

Yeah lets talk about this!

So there is :auto and :manual like you mention, they have the advantage of running async, then there is :shared and it has the limitation of not allowing async tests. These differences and nuances are covered in the article I shared so I won’t go over them.

The point here is that running tests synchronously is the trade-off from using :shared, but that does not mean that :shared is less capable, it simply offers different advantages.

For example, you can’t easily use setup_all/1 with :manual or :auto modes. In :manual you need to create an allowance for each test, whilst in :auto you have to use on_exit/2 callback to manually clean-up all of the changes on the database from your setup_all/1 block.

I suppose you don’t use setup_all much so you have no need to worry about these issues?

I don’t think it is easy to tell what people probably want without being nuanced with these topics. :grin:

Sleepful

Sleepful OP

So tell me about your experience with :manual mode, any quirks that you have ran into? Do you have to write allowances often?

Another of the tricky points with :manual mode is that if your production code uses concurrent queries to the database, then you cannot write allowances for those processes from your test files.

Sleepful

Sleepful OP

This makes me think of another question… Can you mix modes for different tests or is that bound to cause chaos?

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
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
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New

Other Trending Topics Top

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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
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
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews