Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

REFACTOR (ci): Shard the physical end-to-end tests and the WAL usecases package by weighted test names on 4 vCPU runners, since each one slow package bounded its whole backend test group

Rostislav Dugina5a1221f7c02
diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml
index 0574ad53..12e99a04 100644
--- a/.github/workflows/ci-release.yml
+++ b/.github/workflows/ci-release.yml
@@ -298,12 +298,30 @@ jobs:
# 22.04 runs Linux 6.8. ubuntu-24.04 moved to Linux 7.0, where mongod 9.0 exits at startup:
# its kernel check reads Ubuntu's 7.0.0 release string as an rseq-incompatible kernel
# (SERVER-121912, SERVER-136848).
- runs-on: namespace-profile-8vcpu-16ram-ubuntu-22-x64
+ runs-on: ${{ matrix.runner }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
- group: [physical, logical, other]
+ # Only other runs many packages at once. The rest run one to four packages, so twice the
+ # vCPU would only hold a larger share of the concurrency limit.
+ include:
+ - group: other
+ runner: namespace-profile-8vcpu-16ram-ubuntu-22-x64
+ - group: logical
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
+ - group: physical-1-of-3
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
+ - group: physical-2-of-3
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
+ - group: physical-3-of-3
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
+ - group: wal-usecases-1-of-3
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
+ - group: wal-usecases-2-of-3
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
+ - group: wal-usecases-3-of-3
+ runner: namespace-profile-4vcpu-8ram-ubuntu-22-x64
steps:
- name: Check out code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
@@ -400,12 +418,13 @@ jobs:
TEST_GROUP: ${{ matrix.group }}
run: |
cd backend
- # A separate assignment lets a failing recipe stop the step instead of running no packages.
+ # Separate assignments let a failing recipe stop the step instead of running no tests.
packages=$(just test-group-packages "$TEST_GROUP")
- # Each leg runs one group on its own runner. 8 workers oversubscribe its 4 vCPU, so a
- # group needs more wall-clock than the 15m scripts/test.sh allows on a developer machine.
+ run_pattern=$(just test-group-tests "$TEST_GROUP")
+ # Each leg runs one group on its own runner, so a group needs more wall-clock than the
+ # 15m scripts/test.sh allows on a developer machine.
# shellcheck disable=SC2086 # one import path per word
- go test -p=8 -count=1 -failfast -timeout 40m $packages
+ go test -p=8 -count=1 -failfast -timeout 40m ${run_pattern:+-run "$run_pattern"} $packages
build-storage-image:
if: github.head_ref != 'develop'
diff --git a/backend/Justfile b/backend/Justfile
index ec695bcc..1f82a7d9 100644
--- a/backend/Justfile
+++ b/backend/Justfile
@@ -17,18 +17,70 @@ test-package +packages:
apply_libedit_shim
go test -count=1 {{ packages }}
-# CI runs one group per runner, so the three groups must cover every package exactly once. The
-# other group drops only the physical and logical subtrees, so a new package lands in it.
+# CI runs one group per runner, so the groups must cover every package exactly once. The other
+# group drops only the subtrees the named groups take, so a new package lands in it. A group named
+# <name>-<shard>-of-<count> runs one shard of <name>'s packages, see test-group-tests.
test-group-packages group:
#!/usr/bin/env bash
set -euo pipefail
- case "{{ group }}" in
+ group_name=$(sed -E 's/-[0-9]+-of-[0-9]+$//' <<<"{{ group }}")
+ case "$group_name" in
physical) go list ./internal/features/tests/physical/... ;;
logical) go list ./internal/features/tests/logical/... ;;
- other) go list ./internal/... | grep -Ev '/internal/features/tests/(physical|logical)(/|$)' ;;
- *) echo "unknown test group: {{ group }} (expected physical, logical or other)" >&2; exit 1 ;;
+ wal-usecases) go list ./internal/features/backups/backups/usecases/physical/postgresql ;;
+ other)
+ go list ./internal/... |
+ grep -Ev '/internal/features/(tests/(physical|logical)(/|$)|backups/backups/usecases/physical/postgresql$)'
+ ;;
+ *) echo "unknown test group: {{ group }} (expected physical, logical, wal-usecases or other)" >&2; exit 1 ;;
esac
+# A single slow package bounds its group however the packages are spread, so a sharded group splits
+# the top-level tests of its packages instead. Each test goes to exactly one shard, the least-loaded
+# one by the weights in test-shard-weights.txt. Prints a -run pattern, or nothing for a group that
+# is not sharded.
+test-group-tests group:
+ #!/usr/bin/env bash
+ set -euo pipefail
+ if [[ ! "{{ group }}" =~ -([0-9]+)-of-([0-9]+)$ ]]; then
+ exit 0
+ fi
+ shard=${BASH_REMATCH[1]}
+ shard_count=${BASH_REMATCH[2]}
+ if ((shard < 1 || shard > shard_count)); then
+ echo "shard ${shard} is outside 1..${shard_count} in test group {{ group }}" >&2
+ exit 1
+ fi
+ packages=$(just test-group-packages "{{ group }}")
+ # go test -list would run each package's TestMain, which starts its database containers, so
+ # the names come from the test sources.
+ # shellcheck disable=SC2086 # one import path per word
+ package_directories=$(go list -f '{{{{ .Dir }}' $packages)
+ shopt -s nullglob
+ test_files=()
+ for package_directory in $package_directories; do
+ test_files+=("$package_directory"/*_test.go)
+ done
+ test_names=$(
+ grep -hoE '^func (Test|Example|Fuzz)[A-Za-z0-9_]*' "${test_files[@]}" | sed 's/^func //' | grep -vx 'TestMain' | sort -u
+ )
+ shard_names=$(
+ awk 'NR == FNR { if ($0 !~ /^#/ && NF == 2) weights[$2] = $1; next } { print ($1 in weights ? weights[$1] : 1), $1 }' \
+ test-shard-weights.txt - <<<"$test_names" |
+ sort -k1,1nr -k2,2 |
+ awk -v shard="$shard" -v count="$shard_count" '{
+ lightest = 1
+ for (candidate = 2; candidate <= count; candidate++) if (load[candidate] < load[lightest]) lightest = candidate
+ load[lightest] += $1
+ if (lightest == shard) print $2
+ }'
+ )
+ if [[ -z "$shard_names" ]]; then
+ echo "shard ${shard} of ${shard_count} in test group {{ group }} has no tests" >&2
+ exit 1
+ fi
+ echo "^($(paste -sd'|' <<<"$shard_names"))\$"
+
clean-testcontainers:
#!/usr/bin/env bash
set -euo pipefail
diff --git a/backend/test-shard-weights.txt b/backend/test-shard-weights.txt
new file mode 100644
index 00000000..da74a30a
--- /dev/null
+++ b/backend/test-shard-weights.txt
@@ -0,0 +1,31 @@
+# Seconds a test took in one local run, read by the test-group-tests recipe in Justfile. A sharded
+# group deals its slowest tests first so each lands on the least-loaded shard, and a test missing
+# here counts as one second. The values only balance the shards: a stale one makes a shard slower,
+# never skips a test.
+151 Test_WalStream_WhenSourceIsIdle_KeepsReceiverAliveAndDoesNotRebuildSlot
+109 Test_PhysicalWalStream_WhenTheBastionDiesMidStream_KeepsTheSlotAndResumes
+93 Test_WalStream_WhenUploadsKeepFailing_AlertsArchiveStaleOnce
+29 Test_PhysicalRestore_OverSshTunnel_RecoversToTarget
+27 Test_PhysicalBackup_AfterPromotion_ReanchorsIncrementalChain
+25 Test_PhysicalRestore_FullTwoIncrementalsPlusWal_RecoversToTarget
+20 Test_PhysicalRestore_WhenOrphanSweepRunsAfterFull_TargetPastFullStaysRestorable
+18 Test_PhysicalRestore_FullPlusTwoIncrementals_RecoversAllRows
+18 Test_PhysicalRestore_WhenWalGapBeforeTarget_TokenRequestReturns422
+16 Test_PhysicalRestore_FullOnly_RecoversBaseRows
+15 Test_PhysicalWalSlot_WhenDatabaseDeletedWithStreamedWal_SlotRemovedSoNoWalStuck
+14 Test_PhysicalRestore_PitrBootViaEntrypointVolumeMount_RecoversToTarget
+13 Test_WalStreamOverMtls_StreamerArchivesSegments
+12 Test_ByteStallWatcher_WhenNoBytesBeforeFirstByteTimeout_DoesNotTrip
+12 Test_PhysicalMtls_ReplicationConnectionAndSlot_Succeeds
+11 Test_FullOverMtls_ProducesArtifactAndManifest
+11 Test_PhysicalMtls_MissingClientCert_Rejected
+11 Test_PhysicalWalStream_OnTimelineSwitch_CatalogsHistoryOnParentDatabaseID
+10 Test_ByteStallWatcher_WhenFirstByteTimeoutExceeded_Trips
+10 Test_ByteStallWatcher_WhenStallAfterFirstByte_TripsOnStallTimeout
+10 Test_ProbeSlot_WhenSourceAcceptsButNeverAnswers_ReportsUnreachableWithinTimeout
+10 Test_WalStream_SlotLagGrowsWithoutConsumer_DrainsOnceStreaming
+9 Test_PhysicalWalSlot_AppearsWhenBackupingStarts_RemovedWhenDatabaseDeleted
+8 Test_WalStream_WhenSwitchWalIsRefused_AlertsOnceAndStopsRotating
+7 Test_PhysicalRestore_BootViaEntrypointVolumeMount_RecoversBaseRows
+6 Test_RunStartupCleanup_WhenTheSourceIsBehindABastion_DropsOrphanSlots
+5 Test_BackupSlot_RetryAfterFailure_ReusesName