-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[Playground] Start Google Cloud Datastore emulator from Go tests automatically #25791
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
Conversation
f791bdf to
a918a3b
Compare
a918a3b to
5c8e21a
Compare
5c8e21a to
55ceaa4
Compare
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
Assigning reviewers. If you would like to opt out of this review, comment R: @Abacn for label build. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
Reminder, please take a look at this pr: @Abacn |
03c4350 to
a51b6ca
Compare
|
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment R: @damccorm for label build. Available commands:
|
a51b6ca to
0057c56
Compare
| clientCloseErr := ed.Datastore.Client.Close() | ||
| emulatorStopErr := ed.emulator.Stop() |
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.
Usually in go it makes sense to evaluate one error at a time. I wonder if it makes sense to instead call Client.Close and emulator.Stop within the test code itself, or some shared teardown method used by all the tests.
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 would just move the same problem but to a different place - any error during Client.Close() code will prevent a call to emulator.Stop().
| return EmulatedDatastore{Datastore: datastoreDb, emulator: emulator}, nil | ||
| } | ||
|
|
||
| func startEmulator() (*emulator, error) { |
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.
It may make your code cleaner and easy to troubleshoot if you receive a ctx context.Context and use the pattern:
ctx, cancel := context.WithCancel(ctx)
defer cancel()
The test could perhaps do:
ctx, cancel := context.WithTimeout(...)
Would you like me to create an example? Please let me know.
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.
If I understand you correctly, you basically are suggesting to use context cancellation to kill the emulator process, right?
I've tried this approach, but sadly it doesn't work that well as cancelling the context only terminates the first process in the child process tree (starting the datastore emulator creates at least three processes), and the actual emulator process gets reparented by the init. The current code works around this problem by creating a process group out of all emulator processes and sending the SIGTERM to the whole group.
| clientCloseErr := datastoreDb.Close() | ||
| if clientCloseErr != nil { | ||
| panic(clientCloseErr) |
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.
Perhaps these errors could be collected in chan error and handled like:
for {
select {
case err := <- clientErr:
// gracefully shut down other processes
return err
case err := <- datastoreDbErr:
// gracefully shut down other processes
return 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.
We don't have any other processes here and I don't think there is much merit in complicating the error handling situation here with channels. Current code, while not exactly following Go conventions to the letter, is cleaner in my opinion.
damondouglas
left a comment
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.
@damccorm LGTM as MVP; needs clean up later
Start Google Datastore emulator from Go tests automatically
resolves #25588
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.