Skip to content

Commit 65b69b4

Browse files
authored
Allow running integration tests with coverage locally (#151)
1 parent d48c04a commit 65b69b4

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ pgbench -t 1000 -p 6432 -h 127.0.0.1 --protocol extended
8787

8888
See [sharding README](./tests/sharding/README.md) for sharding logic testing.
8989

90+
Run `cargo test` to run Rust tests.
91+
92+
Run the following commands to run Integration tests locally.
93+
```
94+
cd tests/docker/
95+
docker compose up --exit-code-from main # This will also produce coverage report under ./cov/
96+
```
97+
9098
| **Feature** | **Tested in CI** | **Tested manually** | **Comments** |
9199
|-----------------------|--------------------|---------------------|--------------------------------------------------------------------------------------------------------------------------|
92100
| 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.
447455

448456
```
449457
$ pgbench -t 1000 -c 16 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
450-
Password:
458+
Password:
451459
starting vacuum...end.
452460
transaction type: <builtin: select only>
453461
scaling factor: 1
@@ -461,7 +469,7 @@ tps = 139443.955722 (including connections establishing)
461469
tps = 142314.859075 (excluding connections establishing)
462470
463471
$ pgbench -t 1000 -c 32 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
464-
Password:
472+
Password:
465473
starting vacuum...end.
466474
transaction type: <builtin: select only>
467475
scaling factor: 1
@@ -475,7 +483,7 @@ tps = 150644.840891 (including connections establishing)
475483
tps = 152218.499430 (excluding connections establishing)
476484
477485
$ pgbench -t 1000 -c 64 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
478-
Password:
486+
Password:
479487
starting vacuum...end.
480488
transaction type: <builtin: select only>
481489
scaling factor: 1
@@ -489,7 +497,7 @@ tps = 152517.663404 (including connections establishing)
489497
tps = 153319.188482 (excluding connections establishing)
490498
491499
$ pgbench -t 1000 -c 128 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
492-
Password:
500+
Password:
493501
starting vacuum...end.
494502
transaction type: <builtin: select only>
495503
scaling factor: 1

tests/docker/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM rust:bullseye
2+
3+
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
4+
RUN cargo install cargo-binutils rustfilt
5+
RUN rustup component add llvm-tools-preview

tests/docker/docker-compose.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: "3"
2+
services:
3+
pg1:
4+
image: postgres:14
5+
network_mode: "service:main"
6+
environment:
7+
POSTGRES_USER: postgres
8+
POSTGRES_DB: postgres
9+
POSTGRES_PASSWORD: postgres
10+
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
11+
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "5432"]
12+
pg2:
13+
image: postgres:14
14+
network_mode: "service:main"
15+
environment:
16+
POSTGRES_USER: postgres
17+
POSTGRES_DB: postgres
18+
POSTGRES_PASSWORD: postgres
19+
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
20+
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "7432"]
21+
pg3:
22+
image: postgres:14
23+
network_mode: "service:main"
24+
environment:
25+
POSTGRES_USER: postgres
26+
POSTGRES_DB: postgres
27+
POSTGRES_PASSWORD: postgres
28+
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
29+
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "8432"]
30+
pg4:
31+
image: postgres:14
32+
network_mode: "service:main"
33+
environment:
34+
POSTGRES_USER: postgres
35+
POSTGRES_DB: postgres
36+
POSTGRES_PASSWORD: postgres
37+
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
38+
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all", "-p", "9432"]
39+
main:
40+
build: .
41+
command: ["bash", "/app/tests/docker/run.sh"]
42+
environment:
43+
RUSTFLAGS: "-C instrument-coverage"
44+
LLVM_PROFILE_FILE: "pgcat-%m.profraw"
45+
volumes:
46+
- ../../:/app/
47+
- /app/target/

tests/docker/run.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
rm /app/*.profraw || true
4+
rm /app/pgcat.profdata || true
5+
rm -rf /app/cov || true
6+
7+
cd /app/
8+
9+
cargo build
10+
cargo test --tests
11+
12+
bash .circleci/run_tests.sh
13+
14+
rust-profdata merge -sparse pgcat-*.profraw -o pgcat.profdata
15+
16+
rust-cov export -ignore-filename-regex="rustc|registry" -Xdemangler=rustfilt -instr-profile=pgcat.profdata --object ./target/debug/pgcat --format lcov > ./lcov.info
17+
18+
genhtml lcov.info --output-directory cov --prefix $(pwd)
19+
20+
rm /app/*.profraw
21+
rm /app/pgcat.profdata

0 commit comments

Comments
 (0)