Introduction to Sandboxes
Explore how to enhance your Elixir test suite performance by using sandboxes. Understand how sandboxed testing isolates database states for each test and enables concurrent execution to significantly reduce test times.
We'll cover the following...
This chapter explains how to turbo-charge our test suite with sandboxes.
Sandboxes allow us to run our database tests concurrently while still keeping the database state of each test isolated from the others. There is a special pool of database connections with an ownership mechanism that allows us to control how connections are used and shared between processes. When we use a sandbox, it can significantly reduce the time it takes to run our test suite, so we should take advantage of this feature.
What we’ll learn
We’ll walk through the basics of setting up sandboxes and what to do if our tests need connections shared across multiple processes. By the end, our machine will be running through our test suite at top speed—we’ll need to find another excuse to get coffee.