Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
run pg tests on macos and windows in CI
  • Loading branch information
hugodutka committed Dec 2, 2024
commit 56867715ba3b046b0b4b13a3f781c8f9e057783d
41 changes: 33 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,17 @@ jobs:
api-key: ${{ secrets.DATADOG_API_KEY }}

test-go-pg:
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
needs:
- changes
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xlarge' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
# This timeout must be greater than the timeout set by `go test` in
# `make test-postgres` to ensure we receive a trace of running
# goroutines. Setting this to the timeout +5m should work quite well
# even if some of the preceding steps are slow.
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-2022
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
Expand All @@ -400,8 +402,31 @@ jobs:
env:
POSTGRES_VERSION: "13"
TS_DEBUG_DISCO: "true"
shell: bash
run: |
make test-postgres
# if macOS, install google-chrome for scaletests
# As another concern, should we really have this kind of external dependency
# requirement on standard CI?
if [ "${{ matrix.os }}" == "macos-latest" ]; then
brew install google-chrome
fi

# By default Go will use the number of logical CPUs, which
# is a fine default.
PARALLEL_FLAG=""

# macOS will output "The default interactive shell is now zsh"
# intermittently in CI...
if [ "${{ matrix.os }}" == "macos-latest" ]; then
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
fi

if [ "${{ runner.os }}" == "Linux" ]; then
make test-postgres
else
go run scripts/embedded-pg/main.go
DB=ci gotestsum --format standard-quiet -- -v -short -count=1 ./...
fi

- name: Upload test stats to Datadog
timeout-minutes: 1
Expand Down
63 changes: 63 additions & 0 deletions scripts/embedded-pg/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Start an embedded postgres database on port 5432. Used in CI on macOS and Windows.
package main

import (
"database/sql"
"os"
"path/filepath"

embeddedpostgres "github.com/fergusstrange/embedded-postgres"
)

func main() {
postgresPath := filepath.Join(os.TempDir(), "coder-test-postgres")
ep := embeddedpostgres.NewDatabase(
embeddedpostgres.DefaultConfig().
Version(embeddedpostgres.V16).
BinariesPath(filepath.Join(postgresPath, "bin")).
DataPath(filepath.Join(postgresPath, "data")).
RuntimePath(filepath.Join(postgresPath, "runtime")).
CachePath(filepath.Join(postgresPath, "cache")).
Username("postgres").
Password("postgres").
Database("postgres").
Port(uint32(5432)).
Logger(os.Stdout),
)
err := ep.Start()
if err != nil {
panic(err)
}
// We execute these queries instead of using the embeddedpostgres
// StartParams because it doesn't work on Windows. The library
// seems to have a bug where it sends malformed parameters to
// pg_ctl. It encloses each parameter in single quotes, which
// Windows can't handle.
Comment on lines +41 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we open a PR upstream to fix this bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I opened fergusstrange/embedded-postgres#145 and I could submit a PR later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the issue tracking link to this comment?

paramQueries := []string{
`ALTER SYSTEM SET effective_cache_size = '1GB';`,
`ALTER SYSTEM SET fsync = 'off';`,
`ALTER SYSTEM SET full_page_writes = 'off';`,
`ALTER SYSTEM SET max_connections = '1000';`,
`ALTER SYSTEM SET shared_buffers = '1GB';`,
`ALTER SYSTEM SET synchronous_commit = 'off';`,
}
db, err := sql.Open("postgres", "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable")
if err != nil {
panic(err)
}
for _, query := range paramQueries {
if _, err := db.Exec(query); err != nil {
panic(err)
}
}
if err := db.Close(); err != nil {
panic(err)
}
// We restart the database to apply all the parameters.
if err := ep.Stop(); err != nil {
panic(err)
}
if err := ep.Start(); err != nil {
panic(err)
}
}