Skip to content

Commit

Permalink
Consolidate DB init and tests, add justfile
Browse files Browse the repository at this point in the history
* Add justfile to simplify running all the tests
* Save all PBF outputs to the text files
* Consolidate all tests to reuse the same code
* Consolidate database initialization
* updated readme with the new instructions
  • Loading branch information
nyurik committed Oct 28, 2022
1 parent 01b9fe4 commit db3b005
Show file tree
Hide file tree
Showing 66 changed files with 314,449 additions and 143 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Dockerfile

pg_data/
config.yml
tests/output/
34 changes: 18 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install fmt & clippy
run: rustup component add clippy rustfmt

- name: Run cargo fmt
run: cargo fmt --all -- --check

- name: Run cargo clippy
run: cargo clippy --all-targets --all-features -- -D warnings

Expand All @@ -38,7 +35,7 @@ jobs:
PGUSER: postgres
services:
postgres:
image: postgis/postgis:14-3.1-alpine
image: postgis/postgis:14-3.3-alpine
env:
# POSTGRES_* variables are used by the postgis/postgres image
POSTGRES_DB: ${{ env.PGDATABASE }}
Expand All @@ -63,26 +60,31 @@ jobs:
- name: Run tests
run: cargo test --all
env:
DATABASE_URL: postgres://postgres@localhost:${{ job.services.postgres.ports[5432] }}/db
DATABASE_URL: postgres://${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}

- name: Run build
run: cargo build

- name: Run martin with pg auto-discovery
run: ./target/debug/martin --default-srid 900913 &
- name: Run martin tests
run: ./tests/test.sh
env:
DATABASE_URL: postgres://postgres@localhost:${{ job.services.postgres.ports[5432] }}/db
MARTIN_BIN: ./target/debug/martin
DATABASE_URL: postgres://${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}

- name: Test auto-discovered source responses
run: tests/test-auto-sources.sh
- name: Compare test output results (TODO)
if: false
run: |
# TODO: this test is currently broken because the output of the tests is not deterministic
diff --brief --recursive --new-file tests/output tests/expected
- name: Run server with config, overriding connection
run: pkill martin && ./target/debug/martin --config ./tests/config.yaml "$CONNECTION" &
env:
CONNECTION: postgres://postgres@localhost:${{ job.services.postgres.ports[5432] }}/db
- name: 'Save test output on failure'
if: failure()
uses: actions/upload-artifact@v3
with:
name: test-output
path: tests/output/*
retention-days: 5

- name: Test pre-configured source responses
run: tests/test-configured-sources.sh

build:
needs: [test]
Expand Down
29 changes: 14 additions & 15 deletions .github/workflows/grcov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ name: Code coverage
jobs:
grcov:
runs-on: ubuntu-latest
env:
# PG_* variables are used by psql
PGDATABASE: test
PGHOST: localhost
PGUSER: postgres
services:
postgres:
image: postgis/postgis:13-3.1-alpine
image: postgis/postgis:14-3.3-alpine
env:
POSTGRES_DB: test
POSTGRES_USER: postgres
# POSTGRES_* variables are used by the postgis/postgres image
POSTGRES_DB: ${{ env.PGDATABASE }}
POSTGRES_USER: ${{ env.PGUSER }}
POSTGRES_HOST_AUTH_METHOD: trust
ports:
# will assign a random free host port
- 5432/tcp
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout sources
Expand All @@ -28,18 +36,9 @@ jobs:
- name: Setup database
run: |
sudo apt-get install postgresql-client
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/TileBBox.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/table_source.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/table_source_multiple_geom.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/function_source.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/function_source_query_params.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/points1_source.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/points2_source.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/points3857_source.sql
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -d test -f tests/fixtures/points_empty_srid_source.sql
tests/fixtures/initdb.sh
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
PGPORT: ${{ job.services.postgres.ports[5432] }}

- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@master
Expand All @@ -53,7 +52,7 @@ jobs:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
DATABASE_URL: postgres://postgres@localhost:${{ job.services.postgres.ports[5432] }}/test
DATABASE_URL: postgres://${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}

- name: Gather coverage data
id: coverage
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

pg_data/
config.yml
tests/output/
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,22 +762,35 @@ martin postgres://postgres@localhost/db

## Development

Clone project
* Clone Martin
* Install [docker](https://docs.docker.com/get-docker/), [docker-compose](https://docs.docker.com/compose/), and [Just](https://github.com/casey/just#readme) (improved makefile processor)
* Run `just` to see available commands:

```shell
git clone git@github.com:maplibre/martin.git
cd martin
```shell, ignore
❯ git clone git@github.com:maplibre/martin.git
❯ cd martin
❯ just
Available recipes:
bench # Run benchmark tests
clean # Perform cargo clean to delete all build files
clean-test # Delete test output files
run # Start Martin server and a test database
start-db # Start a test database
stop # Stop the test database
test # Run all tests using a test database
test-bless # Run integration tests and save its output as the new expected output
test-int # Run integration tests
test-unit # Run Rust unit tests (cargo test)
```

Start `db` service using [docker-compose](https://docs.docker.com/compose/)
### Other useful commands


```shell
# Start db service
docker-compose up -d db
```

Then, after `db` service is ready to accept connections, you can start `martin` with
```shell
# Run Martin server
DATABASE_URL=postgres://postgres@localhost/db cargo run
```

Expand Down
54 changes: 54 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env just --justfile
set shell := ["bash", "-c"]

export DATABASE_URL := "postgres://postgres@localhost/db"
export CARGO_TERM_COLOR := "always"
# export RUST_BACKTRACE := "1"

@_default:
just --list

# Start Martin server and a test database
run: start-db
cargo run

# Perform cargo clean to delete all build files
clean: clean-test
cargo clean

# Delete test output files
clean-test:
rm -rf tests/output

# Start a test database
start-db:
docker-compose up -d db

alias _down := stop
alias _stop-db := stop

# Stop the test database
stop:
docker-compose down

# Run benchmark tests
bench: start-db
cargo bench

# Run all tests using a test database
test: start-db test-unit test-int

# Run Rust unit tests (cargo test)
test-unit: start-db
cargo test

# Run integration tests
test-int: start-db clean-test
tests/test.sh
diff --brief --recursive --new-file tests/output tests/expected

# Run integration tests and save its output as the new expected output
test-bless: start-db clean-test
tests/test.sh
rm -rf tests/expected
mv tests/output tests/expected
Loading

0 comments on commit db3b005

Please sign in to comment.