This is a casual test suite that displays common anomalies possible at each isolation level in Postgres, as well as ways to avoid them. It is meant to be a companion repository to this article.
The suite is written in Ruby with ActiveRecord as an ORM and RSpec as the testing framework. It is located in the spec/vignettes directory and is separated into multiple subdirectories, each dedicated to a specific isolation level, where each spec file represents a particular situation that shows the possibility or impossibility of an anomaly.
Next to each file containing the source code is a log file containing the generated SQL code formatted and tagged in such a way that the order of operations is clear.
Shortcuts:
- Atomicity
- Read Committed isolation level
- Repeatable Read isolation level
- Serializable isolation level
Use the article as a cohesive narrative for best experience.
Start docker-compose with a Postgres server:
docker-compose -f test.docker-compose.yml -p postgres_anomalies_test upThe suite can then be run using a local Ruby installation via:
bundle exec rspecAlternatively, the suite can be run from within the container:
docker-compose -f test.docker-compose.yml -p postgres_anomalies_test run postgres-anomalies-test-suite bundle exec rspec