Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ concurrent access to **any instance of a model**. Their coarseness means they
aren't going to be commonly applicable, and they can be a source of
[deadlocks](http://en.wikipedia.org/wiki/Deadlock).

## Running Tests

To setup the project and run the whole test suite:

1. Have Docker running
2. `echo -e "DB_USER=with_advisory\nDB_PASSWORD=with_advisory_pass\nDB_NAME=with_advisory_lock_test\nDATABASE_URL_PG=postgres://\$DB_USER:\$DB_PASSWORD@localhost:5433/\$DB_NAME\nDATABASE_URL_MYSQL=mysql2://\$DB_USER:\$DB_PASSWORD@127.0.0.1:3366/\$DB_NAME" > .env`
3. `make`

Alternatively to `make`, run `bin/rails test` to skip database and dependency setup.

## FAQ

### Transactions and Advisory Locks
Expand Down
14 changes: 8 additions & 6 deletions bin/setup_test_db
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

require 'bundler/setup'
require 'active_record'
require 'dotenv'
Dotenv.load

# Setup PostgreSQL database
puts 'Setting up PostgreSQL test database...'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
host: 'localhost',
port: 5433,
database: 'with_advisory_lock_test',
username: 'with_advisory',
password: 'with_advisory_pass'
database: ENV['DB_NAME'],
username: ENV['DB_USER'],
password: ENV['DB_PASSWORD']
)

ActiveRecord::Schema.define(version: 1) do
Expand All @@ -36,9 +38,9 @@ ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
host: '127.0.0.1',
port: 3366,
database: 'with_advisory_lock_test',
username: 'with_advisory',
password: 'with_advisory_pass'
database: ENV['DB_NAME'],
username: ENV['DB_USER'],
password: ENV['DB_PASSWORD']
)

ActiveRecord::Schema.define(version: 1) do
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ services:
pg:
image: postgres:17-alpine
environment:
POSTGRES_USER: with_advisory
POSTGRES_PASSWORD: with_advisory_pass
POSTGRES_DB: with_advisory_lock_test
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
ports:
- "5433:5432"
mysql:
image: mysql:8
environment:
MYSQL_USER: with_advisory
MYSQL_PASSWORD: with_advisory_pass
MYSQL_DATABASE: with_advisory_lock_test
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ROOT_HOST: '%'
ports:
Expand Down