April 2019
Beginner to intermediate
244 pages
6h 34m
English
To work around the limitations of shared mode, Ecto provides a mechanism called allowances. This allows us to pick and choose which processes we share our database connection with. We can keep a single database connection for all processes needed for our test, and be sure that the database state is isolated from any other tests running concurrently.
Let’s go back to the test we looked at in the last section:
| | test "insert album" do |
| | task = Task.async(fn -> |
| | album = MusicDB.Repo.insert!(%MusicDB.Album{title: "Giant Steps"}) |
| | album.id |
| | end) |
| | |
| | album_id = Task.await(task) |
| | assert MusicDB.Repo.get(MusicDB.Album, album_id).title ... |
Read now
Unlock full access