Skip to content

Conversation

@TSultanov
Copy link
Contributor

@TSultanov TSultanov commented Mar 10, 2023

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:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI.

@TSultanov TSultanov force-pushed the autostart-datastore-emulator branch 5 times, most recently from f791bdf to a918a3b Compare March 10, 2023 12:17
@TSultanov TSultanov marked this pull request as ready for review March 10, 2023 12:29
@TSultanov TSultanov force-pushed the autostart-datastore-emulator branch from a918a3b to 5c8e21a Compare March 10, 2023 13:45
@TSultanov TSultanov changed the title Start Google Cloud Datastore emulator from Go tests automatically [Playground] Start Google Cloud Datastore emulator from Go tests automatically Mar 13, 2023
@TSultanov TSultanov force-pushed the autostart-datastore-emulator branch from 5c8e21a to 55ceaa4 Compare March 23, 2023 08:51
@github-actions github-actions bot added the build label Mar 23, 2023
@github-actions
Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@github-actions
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @Abacn for label build.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@github-actions
Copy link
Contributor

Reminder, please take a look at this pr: @Abacn

@TSultanov TSultanov force-pushed the autostart-datastore-emulator branch from 03c4350 to a51b6ca Compare March 30, 2023 13:33
@github-actions github-actions bot added build and removed build labels Mar 30, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @damccorm for label build.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

@TSultanov TSultanov force-pushed the autostart-datastore-emulator branch from a51b6ca to 0057c56 Compare April 5, 2023 11:01
@github-actions github-actions bot added build and removed build labels Apr 5, 2023
Comment on lines 54 to 55
clientCloseErr := ed.Datastore.Client.Close()
emulatorStopErr := ed.emulator.Stop()
Copy link
Contributor

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.

Copy link
Contributor Author

@TSultanov TSultanov Apr 12, 2023

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@TSultanov TSultanov Apr 12, 2023

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.

Comment on lines +60 to +62
clientCloseErr := datastoreDb.Close()
if clientCloseErr != nil {
panic(clientCloseErr)
Copy link
Contributor

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
   }
}

Copy link
Contributor Author

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.

@github-actions github-actions bot removed the build label Apr 12, 2023
@github-actions github-actions bot added the build label Apr 12, 2023
@github-actions github-actions bot added build and removed build labels Apr 12, 2023
Copy link
Contributor

@damondouglas damondouglas left a 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

@damccorm damccorm merged commit 56f4533 into apache:master Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task][Playground]: Remove need to manually start Datastore emulator for Playground backend tests

3 participants