Skip to content

Commit f363ca7

Browse files
vr009cschleiden
authored andcommitted
feat: add Postgres benchmarking and testing workflows
1 parent 5787158 commit f363ca7

File tree

3 files changed

+137
-3
lines changed

3 files changed

+137
-3
lines changed

.github/workflows/bench.yml

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,92 @@ jobs:
235235
name: redis-results
236236
path: redis-benchmark.md
237237

238+
postgres-bench:
239+
runs-on: ubuntu-latest
240+
if: (github.event_name == 'workflow_dispatch' || (github.event.issue.pull_request && contains(github.event.comment.body, '!bench'))) && !contains(github.event.comment.body, '!skippostgres')
241+
outputs:
242+
pr-sha: ${{ steps.sha.outputs.result || github.sha }}
243+
steps:
244+
- name: Install Hyperfine
245+
run: |
246+
wget https://github.com/sharkdp/hyperfine/releases/download/v1.11.0/hyperfine_1.11.0_amd64.deb
247+
sudo dpkg -i hyperfine_1.11.0_amd64.deb
248+
249+
- name: Get PR SHA
250+
if: github.event_name == 'issue_comment'
251+
id: sha
252+
uses: actions/github-script@v6
253+
with:
254+
result-encoding: string
255+
script: |
256+
const response = await github.request(context.payload.issue.pull_request.url);
257+
return response.data.head.sha;
258+
259+
- name: Checkout PR
260+
uses: actions/checkout@v4
261+
with:
262+
ref: ${{ steps.sha.outputs.result || github.sha }}
263+
264+
- name: Set up Go
265+
uses: actions/setup-go@v5
266+
with:
267+
go-version: 1.24
268+
check-latest: true
269+
cache: true
270+
271+
- name: Build PR
272+
run: |
273+
go build -o bench-pr ./bench
274+
275+
- name: Checkout main branch
276+
uses: actions/checkout@v4
277+
with:
278+
clean: false
279+
ref: main
280+
281+
- name: Build main
282+
run: |
283+
go build -o bench-main ./bench
284+
285+
- name: Start Postgres
286+
uses: ikalnytskyi/action-setup-postgres@v7
287+
with:
288+
username: root
289+
password: root
290+
database: postgres
291+
port: 5432
292+
postgres-version: "16"
293+
294+
- name: Run Postgres benchmarks
295+
run: |
296+
echo "## Postgres run" > postgres-benchmark.md
297+
hyperfine --show-output --warmup 1 --export-markdown bench-postgres.md -n 'postgres-main' './bench-main -runs 2 -backend postgres' -n 'postgres-pr' './bench-pr -runs 2 -backend postgres'
298+
cat bench-postgres.md >> postgres-benchmark.md
299+
300+
- name: Run large Postgres benchmarks
301+
if: contains(github.event.comment.body, '!large')
302+
run: |
303+
echo "## Large Postgres payload run (1MB)" >> postgres-benchmark.md
304+
hyperfine --show-output --warmup 1 --export-markdown bench-postgres-l.md -n 'postgres-main' './bench-main -resultsize 1000000 -activities 10 -runs 2 -backend postgres -timeout 240s' -n 'postgres-pr' './bench-pr -resultsize 1000000 -activities 10 -runs 2 -backend postgres -timeout 240s'
305+
cat bench-postgres-l.md >> postgres-benchmark.md
306+
307+
- name: Run very large Postgres benchmarks
308+
if: contains(github.event.comment.body, '!verylarge')
309+
run: |
310+
echo "## Very Large Postgres payload run (5MB)" >> postgres-benchmark.md
311+
hyperfine --show-output --warmup 1 --export-markdown bench-postgres-vl.md -n 'postgres-main' './bench-main -resultsize 5000000 -runs 2 -backend postgres -timeout 240s' -n 'postgres-pr' './bench-pr -resultsize 5000000 -runs 2 -backend postgres -timeout 240s'
312+
cat bench-postgres-vl.md >> postgres-benchmark.md
313+
314+
- name: Upload Postgres benchmark results
315+
uses: actions/upload-artifact@v4
316+
with:
317+
name: postgres-results
318+
path: postgres-benchmark.md
319+
238320
combine-results:
239321
runs-on: ubuntu-latest
240-
needs: [mysql-bench, sqlite-bench, redis-bench]
241-
if: always() && (needs.mysql-bench.result == 'success' || needs.sqlite-bench.result == 'success' || needs.redis-bench.result == 'success') && github.event.issue.pull_request
322+
needs: [mysql-bench, sqlite-bench, redis-bench, postgres-bench]
323+
if: always() && (needs.mysql-bench.result == 'success' || needs.sqlite-bench.result == 'success' || needs.redis-bench.result == 'success' || needs.postgres-bench.result == 'success') && github.event.issue.pull_request
242324
steps:
243325
- name: Download MySQL results
244326
if: needs.mysql-bench.result == 'success'
@@ -264,6 +346,14 @@ jobs:
264346
path: ./results
265347
continue-on-error: true
266348

349+
- name: Download Postgres results
350+
if: needs.postgres-bench.result == 'success'
351+
uses: actions/download-artifact@v4
352+
with:
353+
name: postgres-results
354+
path: ./results
355+
continue-on-error: true
356+
267357
- name: Combine benchmark results
268358
run: |
269359
echo "# Benchmark Results" > combined-benchmark.md
@@ -284,6 +374,11 @@ jobs:
284374
echo "" >> combined-benchmark.md
285375
fi
286376
377+
if [ -f "./results/postgres-benchmark.md" ]; then
378+
cat ./results/postgres-benchmark.md >> combined-benchmark.md
379+
echo "" >> combined-benchmark.md
380+
fi
381+
287382
- name: Write a new comment
288383
uses: peter-evans/create-or-update-comment@v2
289384
continue-on-error: true

.github/workflows/go.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,37 @@ jobs:
142142
paths: |
143143
${{ github.workspace }}/report.xml
144144
if: always()
145+
146+
test_postgres:
147+
runs-on: ubuntu-latest
148+
needs: build
149+
150+
steps:
151+
- uses: actions/checkout@v4
152+
153+
- name: Set up Go
154+
uses: actions/setup-go@v5
155+
with:
156+
go-version: 1.24
157+
check-latest: true
158+
cache: true
159+
160+
- name: Start Postgres
161+
uses: ikalnytskyi/action-setup-postgres@v7
162+
with:
163+
username: root
164+
password: root
165+
database: postgres
166+
port: 5432
167+
postgres-version: "16"
168+
169+
- name: Tests
170+
run: |
171+
go test -timeout 240s -race -count 1 -v github.com/cschleiden/go-workflows/backend/postgres 2>&1 | go tool go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
172+
173+
- name: Test Summary
174+
uses: test-summary/action@v2
175+
with:
176+
paths: |
177+
${{ github.workspace }}/report.xml
178+
if: always()

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ test-mysql:
4747
@echo "Running MySQL backend tests..."
4848
$(GOTEST) $(TEST_FLAGS) -timeout $(TEST_TIMEOUT) github.com/cschleiden/go-workflows/backend/mysql
4949

50+
# Run Postgres backend tests
51+
test-postgres:
52+
@echo "Running Postgres backend tests..."
53+
$(GOTEST) $(TEST_FLAGS) -timeout $(TEST_TIMEOUT) github.com/cschleiden/go-workflows/backend/postgres
54+
5055
# Run SQLite backend tests
5156
test-sqlite:
5257
@echo "Running SQLite backend tests..."
@@ -58,7 +63,7 @@ test-monoprocess:
5863
$(GOTEST) $(TEST_FLAGS) -timeout $(TEST_TIMEOUT) github.com/cschleiden/go-workflows/backend/monoprocess
5964

6065
# Run all backend tests
61-
test-backends: test-redis test-mysql test-sqlite test-monoprocess
66+
test-backends: test-redis test-mysql test-sqlite test-monoprocess test-postgres
6267

6368
custom-gcl:
6469
@echo "Checking if golangci-lint is installed..."

0 commit comments

Comments
 (0)