-
Notifications
You must be signed in to change notification settings - Fork 518
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
fix test race condition; remove verbose global #457
Conversation
@@ -11,6 +11,20 @@ import ( | |||
"sync" | |||
) | |||
|
|||
type Direction string |
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.
The ParseSQLMigration
took 2 booleans with a signature like (r io.Reader, direction, verbose bool)
.
It's waaaay too easy for the caller to mix up the booleans, so instead, the second param is now a well-defined type to avoid any footguns.
@@ -23,15 +37,37 @@ const ( | |||
gooseStatementEndDown // 6 | |||
) | |||
|
|||
type stateMachine parserState | |||
type stateMachine struct { |
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.
I think it makes sense to attach the verbose bool
to the struct and hang a print helper.
We pass around the stateMachine
struct as a pointer.
@@ -73,6 +74,11 @@ func TestMain(m *testing.M) { | |||
migrationsDir = filepath.Join("testdata", *dialect, "migrations") | |||
seedDir = filepath.Join("testdata", *dialect, "seed") | |||
|
|||
if err := goose.SetDialect(*dialect); err != nil { |
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.
The dialect is set once within the e2e tests, we can do this here in TestMain.
I noticed a race condition in the tests, having to do with setting verbose globally in
sqlparser
.https://github.com/pressly/goose/actions/runs/4032205783/jobs/6931938495
This PR updates the internal/sqlparser. Changes the
stateMachine
to a well-defined struct which we pass around as a pointer. The caller sets the direction (well-defined) and the verbose bool, no more global state in sqlparser.For convenience, one can set env
DEBUG_TEST=true
in tests to see those verbose parsing statements.DEBUG_TEST=true go test -race -count=1 -v -timeout=10m ./internal/sqlparser/...