Skip to content

Commit

Permalink
chore(ci): multiple integration tests per shard in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Dec 19, 2024
1 parent c24e6fe commit ca76ea3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ jobs:
run: |
set -euo pipefail
# shellcheck disable=SC2046
echo "matrix={\"test\":$(jq -c -n '$ARGS.positional' --args $(git grep -l '^//go:build integration' | xargs grep '^func Test' | awk '{print $2}' | cut -d'(' -f1))}" >> "$GITHUB_OUTPUT"
echo "matrix={\"test\":$(jq -c -n '$ARGS.positional' --args $(git grep -l '^//go:build integration' | xargs grep '^func Test' | awk '{print $2}' | cut -d'(' -f1 | paste -d '|' - - | sed 's/|*$//'))}" >> "$GITHUB_OUTPUT"
integration-run:
name: Integration Test
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
Expand All @@ -281,7 +281,7 @@ jobs:
run: |
set -euo pipefail
# shellcheck disable=SC2046
go test -v -race -tags integration -run '^${{ matrix.test }}$' $(git grep -l '^//go:build integration' | xargs grep -l '^func ${{ matrix.test }}' | xargs -I {} dirname ./{})
echo '${{ matrix.test }}' | tr '|' ' ' | xargs -n1 just integration-tests
infrastructure-shard:
name: Shard Infrastructure Tests
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
Expand Down
13 changes: 3 additions & 10 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ format-frontend:

# Install Node dependencies using pnpm
pnpm-install:
#!/bin/bash
set -euo pipefail
for i in {1..3}; do mk frontend/{console,vscode}/node_modules : frontend/{console,vscode}/package.json -- "pnpm install --frozen-lockfile" && break || sleep 5; done
retry 3 pnpm install --frozen-lockfile

# Copy plugin protos from the SQLC release
update-sqlc-plugin-codegen-proto:
Expand All @@ -233,16 +231,11 @@ build-protos-unconditionally: go2proto lint-protos pnpm-install
# Run integration test(s)
integration-tests *test:
#!/bin/bash
set -euo pipefail
testName=${1:-}
for i in {1..3}; do go test -fullpath -count 1 -v -tags integration -run "$testName" -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l "$testName" | xargs grep -l '//go:build integration' | xargs -I {} dirname './{}') && break || true; done
retry 3 /bin/bash -c "go test -fullpath -count 1 -v -tags integration -run {{test}} -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l {{test}} | xargs grep -l '//go:build integration' | xargs -I {} dirname './{}' | tr '\n' ' ')"

# Run integration test(s)
infrastructure-tests *test:
#!/bin/bash
set -euo pipefail
testName=${1:-}
for i in {1..3}; do go test -fullpath -count 1 -v -tags infrastructure -run "$testName" -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l "$testName" | xargs grep -l '//go:build infrastructure' | xargs -I {} dirname './{}') && break || true; done
retry 3 /bin/bash -c "go test -fullpath -count 1 -v -tags infrastructure -run {{test}} -p 1 $(find . -type f -name '*_test.go' -print0 | xargs -0 grep -r -l {{test}} | xargs grep -l '//go:build infrastructure' | xargs -I {} dirname './{}' | tr '\n' ' ')"

# Run README doc tests
test-readme *args:
Expand Down
3 changes: 1 addition & 2 deletions internal/integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"database/sql"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -624,7 +623,7 @@ func JsonData(t testing.TB, body interface{}) []byte {
func HttpCall(method string, path string, headers map[string][]string, body []byte, onResponse func(t testing.TB, resp *HTTPResponse)) Action {
return func(t testing.TB, ic TestContext) {
Infof("HTTP %s %s", method, path)
baseURL, err := url.Parse(fmt.Sprintf("http://localhost:8891"))
baseURL, err := url.Parse("http://localhost:8891")
assert.NoError(t, err)

u, err := baseURL.Parse(path)
Expand Down
21 changes: 21 additions & 0 deletions scripts/retry
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# #
# Retry a command until it succeeds or the maximum number of retries is reached.
# Usage: retry <max-retries> <command>

set -euo pipefail

max_retries=${1:-}
shift

for i in $(seq 1 $max_retries); do

Check failure on line 11 in scripts/retry

View workflow job for this annotation

GitHub Actions / Lint

note: Double quote to prevent globbing and word splitting. [SC2086]
echo "$@"
if "$@"; then
exit 0
fi
if [ "$i" -eq "$max_retries" ]; then
exit 1
fi
echo "Failed, retrying in 5 seconds..."
sleep 5
done

0 comments on commit ca76ea3

Please sign in to comment.