Issues running Google App Engine Datastore emulator

Hi!

I’m trying to configure the Datastore emulator so that I can run my unit tests in Travis’s environment but I’m running into some issues.

When I run locally, I get output like this:

INFO     2019-08-08 13:05:43,747 devappserver2.py:278] Skipping SDK update check.
WARNING  2019-08-08 13:05:43,747 devappserver2.py:294] DEFAULT_VERSION_HOSTNAME will not be set correctly with --port=0
INFO     2019-08-08 13:05:43,899 datastore_emulator.py:155] Starting Cloud Datastore emulator at: http://localhost:15562
WARNING  2019-08-08 13:05:44,022 simple_search_stub.py:1196] Could not read search indexes from /var/folders/yh/yl5fpz3n7z70dvxzgzyznqt1t3tcnt/T/appengine.testapp.e1207786/search_indexes
INFO     2019-08-08 13:05:44,815 datastore_emulator.py:161] Cloud Datastore emulator responded after 0.916363 seconds
INFO     2019-08-08 13:05:44,816 api_server.py:275] Starting API server at: http://localhost:52287
INFO     2019-08-08 13:05:44,820 api_server.py:265] Starting gRPC API server at: http://localhost:52289
INFO     2019-08-08 13:05:44,915 dispatcher.py:256] Starting module "default" running at: http://localhost:52290
INFO     2019-08-08 13:05:44,917 admin_server.py:150] Starting admin server at: http://localhost:52292

However, when I run the same on Travis, I get the following (empty lines indicate where I’m not seeing the same output):

INFO     2019-08-08 02:59:52,702 devappserver2.py:278] Skipping SDK update check.
WARNING  2019-08-08 02:59:52,702 devappserver2.py:294] DEFAULT_VERSION_HOSTNAME will not be set correctly with --port=0

WARNING  2019-08-08 02:59:52,782 simple_search_stub.py:1196] Could not read search indexes from /tmp/appengine.testapp.travis/search_indexes

INFO     2019-08-08 02:59:52,783 api_server.py:275] Starting API server at: http://localhost:37037

INFO     2019-08-08 02:59:52,789 dispatcher.py:256] Starting module "default" running at: http://localhost:44299
INFO     2019-08-08 02:59:52,790 admin_server.py:150] Starting admin server at: http://localhost:39071

Here’s a link to my most recent build; I’m not sure if I’m missing something that still need to be installed prior to running tests or whether there is something preventing the Datastore emulator from actually running (which is what I suspect is the issue since I don’t see those being generated in the output messages).

Here are a couple additional resources I’ve been consulting:

Best,
John

I’m not quite sure what is at play here and I"m unfortunately not familiar with the Google App Engine Datastore emulator.

However, looking at the documentation, it seems that you need to start it with a command like:

gcloud beta emulators datastore start [flags]

Could you give us visibility on where you are calling this command in your build?

Thanks!

So I tried including that in prior and current configurations (I’ve kept everything separate in the commit history for this branch so I can see what’s not/working). Right now, it’s visible here under the before_script step (including &).

Thanks for the response!

Thanks for these details, @forstmeier!

If I look at this build, it seems you have tests using the datastore emulator successfully, am I right? i.e. this succeeds:

go test -v -race github.com/forstmeier/watchmyrepo/helpers -coverprofile=helpers.coverprofile

but this fails:

go test -v -race github.com/forstmeier/watchmyrepo/database -coverprofile=database.coverprofile

Can you look at what’s different in these tests setup?

Sure thing, @dominic !

The only place the emulator is currently being called is in the tests for the watchmyrepo/database package since that’s the only place where the database interface isn’t mocked out (in watchmyrepo/handlers it is mocked out). Because the watchmyrepo/database package would be making the direct calls to Datastore in production it would need the emulator in place in order to effectively mock out those calls in tests.

Why are we seeing

Executing: /usr/lib/google-cloud-sdk/platform/cloud-datastore-emulator/cloud_datastore_emulator create --project_id=travis-ci-prod-2 /home/travis/.config/gcloud/emulators/datastore

in watchmyrepo/helpers but not in watchmyrepo/database?

Excellent question. I don’t know why it would be popping up in that particular command and not in the subsequent tests; could this be a complication arising from the use of the & to run it as a background execution? When I did not include the &, the test timed out.

Would you be interested to try running the build in debug mode? With access to the VM and the intimate understanding of your tools and code base, you are in the best position to troubleshoot this issue further. The debug mode is explained in https://docs.travis-ci.com/user/running-build-in-debug-mode/ and we would be happy to enable it for your repo if you want.

Yes, that would be very helpful, @dominic. I should be able to take a closer look in that mode. Let me know what else you need from me to set that up.

I confirm debug mode is now enabled on your repository. You can follow the instructions in our docs to do an API call to start a debug build where you’ll be able to connect to the VM. Since your repository is open source and on travis-ci.org, please make sure to use the .org API endpoint i.e.

https://api.travis-ci.org/job/${id}/debug

@dominic, awesome, thank you!

I’ve also opened up an issue on StackOverflow to see if I can get some broader Datastore emulator guidance (since that’s likely the root cause of my issue).

Great! Please keep us posted and let us know if you can help you further.