-
Notifications
You must be signed in to change notification settings - Fork 936
chore: run macOS, windows, and race tests with Postgres in CI #15520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5686771
fede550
cd9b4d1
e797183
fb23890
4e3421f
46a8c60
dcfdc07
5d79aea
1c99f2e
de40386
988c893
e7463ec
b41c523
8a61183
d319138
c63786f
ed13154
4b6f183
9c7e240
4969a23
160e77c
f87261f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: "Setup ImDisk" | ||
if: runner.os == 'Windows' | ||
description: | | ||
Sets up the ImDisk toolkit for Windows and creates a RAM disk on drive R:. | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Download ImDisk | ||
if: runner.os == 'Windows' | ||
shell: bash | ||
run: | | ||
mkdir imdisk | ||
cd imdisk | ||
curl -L -o files.cab https://github.com/coder/imdisk-artifacts/raw/92a17839ebc0ee3e69be019f66b3e9b5d2de4482/files.cab | ||
curl -L -o install.bat https://github.com/coder/imdisk-artifacts/raw/92a17839ebc0ee3e69be019f66b3e9b5d2de4482/install.bat | ||
cd .. | ||
|
||
- name: Install ImDisk | ||
shell: cmd | ||
run: | | ||
cd imdisk | ||
install.bat /silent | ||
|
||
- name: Create RAM Disk | ||
shell: cmd | ||
run: | | ||
imdisk -a -s 4096M -m R: -p "/fs:ntfs /q /y" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Start an embedded postgres database on port 5432. Used in CI on macOS and Windows. | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"flag" | ||
"os" | ||
"path/filepath" | ||
|
||
embeddedpostgres "github.com/fergusstrange/embedded-postgres" | ||
) | ||
|
||
func main() { | ||
var customPath string | ||
flag.StringVar(&customPath, "path", "", "Optional custom path for postgres data directory") | ||
flag.Parse() | ||
|
||
postgresPath := filepath.Join(os.TempDir(), "coder-test-postgres") | ||
if customPath != "" { | ||
postgresPath = customPath | ||
} | ||
|
||
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"). | ||
Encoding("UTF8"). | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we open a PR upstream to fix this bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the issue tracking link to this comment? |
||
// Related issue: | ||
// https://github.com/fergusstrange/embedded-postgres/issues/145 | ||
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';`, | ||
`ALTER SYSTEM SET client_encoding = 'UTF8';`, | ||
} | ||
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) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sucks that people still use sourceforge lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's Windows for you