diff --git a/README.md b/README.md index 48f8353..8d4c77f 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,14 @@ pgbench -t 1000 -p 6432 -h 127.0.0.1 --protocol extended See [sharding README](./tests/sharding/README.md) for sharding logic testing. +Run `cargo test` to run Rust tests. + +Run the following commands to run Integration tests locally. +``` +cd tests/docker/ +docker compose up --exit-code-from main # This will also produce coverage report under ./cov/ +``` + | **Feature** | **Tested in CI** | **Tested manually** | **Comments** | |-----------------------|--------------------|---------------------|--------------------------------------------------------------------------------------------------------------------------| | Transaction pooling | :white_check_mark: | :white_check_mark: | Used by default for all tests. | @@ -447,7 +455,7 @@ Always good to have a base line. ``` $ pgbench -t 1000 -c 16 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0 -Password: +Password: starting vacuum...end. transaction type: scaling factor: 1 @@ -461,7 +469,7 @@ tps = 139443.955722 (including connections establishing) tps = 142314.859075 (excluding connections establishing) $ pgbench -t 1000 -c 32 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0 -Password: +Password: starting vacuum...end. transaction type: scaling factor: 1 @@ -475,7 +483,7 @@ tps = 150644.840891 (including connections establishing) tps = 152218.499430 (excluding connections establishing) $ pgbench -t 1000 -c 64 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0 -Password: +Password: starting vacuum...end. transaction type: scaling factor: 1 @@ -489,7 +497,7 @@ tps = 152517.663404 (including connections establishing) tps = 153319.188482 (excluding connections establishing) $ pgbench -t 1000 -c 128 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0 -Password: +Password: starting vacuum...end. transaction type: scaling factor: 1 diff --git a/tests/docker/Dockerfile b/tests/docker/Dockerfile new file mode 100644 index 0000000..1f11efb --- /dev/null +++ b/tests/docker/Dockerfile @@ -0,0 +1,5 @@ +FROM rust:bullseye + +RUN apt-get update && apt-get install llvm-11 psmisc postgresql-contrib postgresql-client ruby ruby-dev libpq-dev python3 python3-pip lcov sudo curl -y +RUN cargo install cargo-binutils rustfilt +RUN rustup component add llvm-tools-preview diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml new file mode 100644 index 0000000..d86e239 --- /dev/null +++ b/tests/docker/docker-compose.yml @@ -0,0 +1,47 @@ +version: "3" +services: + pg1: + image: postgres:14 + network_mode: "service:main" + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: scram-sha-256 + command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "5432"] + pg2: + image: postgres:14 + network_mode: "service:main" + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: scram-sha-256 + command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "7432"] + pg3: + image: postgres:14 + network_mode: "service:main" + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: scram-sha-256 + command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "8432"] + pg4: + image: postgres:14 + network_mode: "service:main" + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: scram-sha-256 + command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "9432"] + main: + build: . + command: ["bash", "/app/tests/docker/run.sh"] + environment: + RUSTFLAGS: "-C instrument-coverage" + LLVM_PROFILE_FILE: "pgcat-%m.profraw" + volumes: + - ../../:/app/ + - /app/target/ diff --git a/tests/docker/run.sh b/tests/docker/run.sh new file mode 100644 index 0000000..ada5d9e --- /dev/null +++ b/tests/docker/run.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +rm /app/*.profraw || true +rm /app/pgcat.profdata || true +rm -rf /app/cov || true + +cd /app/ + +cargo build +cargo test --tests + +bash .circleci/run_tests.sh + +rust-profdata merge -sparse pgcat-*.profraw -o pgcat.profdata + +rust-cov export -ignore-filename-regex="rustc|registry" -Xdemangler=rustfilt -instr-profile=pgcat.profdata --object ./target/debug/pgcat --format lcov > ./lcov.info + +genhtml lcov.info --output-directory cov --prefix $(pwd) + +rm /app/*.profraw +rm /app/pgcat.profdata