diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3be8eedfb..c0d5af86e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,6 +64,7 @@ jobs: run: make bench ITERATIONS=1 build_and_test: + name: build_and_test (${{ matrix.go-version }}, ${{ matrix.postgres-version }}${{ matrix.primary && ', race' || '' }}) env: # The special value "local" tells Go to use the bundled Go version rather # than trying to fetch one according to a `toolchain` value in `go.mod`. @@ -74,9 +75,11 @@ jobs: strategy: matrix: include: - # Run the latest Go version against all supported Postgres versions: + # Run the latest Go version against all supported Postgres versions. + # Only the newest Go/Postgres combination runs with the race detector. - go-version: "1.27" postgres-version: 18 + primary: true - go-version: "1.27" postgres-version: 17 - go-version: "1.27" @@ -128,10 +131,16 @@ jobs: - name: Set up database run: psql -c "CREATE DATABASE river_test" $ADMIN_DATABASE_URL - - name: Test + - name: Test with race detector + if: matrix.primary run: make test/race TEST_DATABASE=postgres + - name: Test + if: ${{ !matrix.primary }} + run: make test TEST_DATABASE=postgres + build_and_test_sqlite: + name: build_and_test_sqlite (${{ matrix.go-version }}${{ matrix.primary && ', race' || '' }}) env: GOTOOLCHAIN: local runs-on: ubuntu-latest @@ -140,6 +149,10 @@ jobs: # Keep both supported Go versions covered without repeating SQLite, # libSQL, and Turso tests for every PostgreSQL version. go-version: ["1.27", "1.26"] + include: + # Only the newest Go version runs with the race detector. + - go-version: "1.27" + primary: true fail-fast: false timeout-minutes: 5 @@ -151,9 +164,14 @@ jobs: with: go-version: ${{ matrix.go-version }} - - name: Test + - name: Test with race detector + if: matrix.primary run: make test/race TEST_DATABASE=sqlite + - name: Test + if: ${{ !matrix.primary }} + run: make test TEST_DATABASE=sqlite + cli: strategy: matrix: diff --git a/Makefile b/Makefile index 22b706e30..58cb24008 100644 --- a/Makefile +++ b/Makefile @@ -47,14 +47,17 @@ TEST_DATABASE ?= all # Only filter the shared driver suite. Other packages have SQLite-named tests # that use PostgreSQL or mocks and should stay in the regular test run. -sqlite_test_pattern := '^(Test.*(LibSQL|SQLite|Turso)|Example_(libSQL|sqlite|turso))' +sqlite_test_pattern := ^(Test.*(LibSQL|SQLite|Turso)|Example_(libSQL|sqlite|turso)) test_submodules := $(submodules) +legacy_driver_test_flags := -run '/WithTx$$' ifeq ($(TEST_DATABASE),postgres) test_submodules := $(filter-out %/riverdriver/riversqlite,$(submodules)) - driver_test_flags := -skip $(sqlite_test_pattern) + driver_test_flags := -skip '$(sqlite_test_pattern)' + legacy_driver_test_flags += -skip '$(sqlite_test_pattern)' else ifeq ($(TEST_DATABASE),sqlite) test_submodules := $(filter %/riverdriver/riverdrivertest %/riverdriver/riversqlite,$(submodules)) - driver_test_flags := -run $(sqlite_test_pattern) + driver_test_flags := -run '$(sqlite_test_pattern)' + legacy_driver_test_flags := -run '$(sqlite_test_pattern)/WithTx$$' else ifneq ($(TEST_DATABASE),all) $(error TEST_DATABASE must be all, postgres, or sqlite) endif @@ -77,8 +80,10 @@ endef $(foreach mod,$(test_submodules),$(eval $(call test-target,$(mod)))) # Exercise the temporary savepoint fallback as well as default transaction reuse. -test:: ; cd ./riverdriver/riverdrivertest && RIVER_USE_LEGACY_SUBTRANSACTIONS=1 go test . -run '/WithTx$$' -timeout 2m +test:: ; cd ./riverdriver/riverdrivertest && RIVER_USE_LEGACY_SUBTRANSACTIONS=1 go test . $(legacy_driver_test_flags) -timeout 2m +ifneq ($(TEST_DATABASE),sqlite) test:: ; cd ./riverdriver/riverdrivertest && RIVER_USE_LEGACY_SUBTRANSACTIONS=1 go test . -run '^TestDriverRiverPgxV5$$/.*/WithTx$$' -timeout 2m +endif .PHONY: test/race test/race:: ## Run tests with race detector (TEST_DATABASE=all, postgres, or sqlite) @@ -87,8 +92,10 @@ define test-race-target endef $(foreach mod,$(test_submodules),$(eval $(call test-race-target,$(mod)))) -test/race:: ; cd ./riverdriver/riverdrivertest && RIVER_USE_LEGACY_SUBTRANSACTIONS=1 go test . -race -run '/WithTx$$' -timeout 2m +test/race:: ; cd ./riverdriver/riverdrivertest && RIVER_USE_LEGACY_SUBTRANSACTIONS=1 go test . -race $(legacy_driver_test_flags) -timeout 2m +ifneq ($(TEST_DATABASE),sqlite) test/race:: ; cd ./riverdriver/riverdrivertest && RIVER_USE_LEGACY_SUBTRANSACTIONS=1 go test . -race -run '^TestDriverRiverPgxV5$$/.*/WithTx$$' -timeout 2m +endif .PHONY: bench bench:: ## Run benchmarks in each submodule (ITERATIONS=100) diff --git a/docs/development.md b/docs/development.md index 45522d480..b3df5b714 100644 --- a/docs/development.md +++ b/docs/development.md @@ -23,7 +23,8 @@ To run the regular suite with the SQLite driver tests excluded: `TEST_DATABASE` also applies to `make test/race`. CI separates these suites so the PostgreSQL version matrix doesn't repeat the SQLite tests. Each suite still -runs on both supported Go versions. +runs on both supported Go versions. Only the latest combination in each matrix +uses the race detector, marked `race` in its job title. ## Run lint