daiyue
daiyue

Reputation: 7448

problems with testing and debugging datastore code in python using py.test

I am unit testing some Python google cloud datastore code using py.test in PyCharm. The code is running locally on datastore emulator.The problem is

  1. I have to put multiple time.sleep(num_secs) after the code that does put_multi(), put() etc, and run the code under debug mode, going line by line to check the results so that assert wouldn't fail, since even if the code runs correctly, the result got back from the emulator using query.fetch() does not reflect the changes in the datastore. I realised that there might be a race condition happening between Python and datastore simulator. Hence a (big?) delay in making the changes effective?
  2. Sometimes, even under debug mode and using emulator, I encountered HTTP Error 404: Service Unavailable. I then have to turn on the Compute Engine VMs, and so the code can be working again, even turn off the VMs afterwards. That is very strange. Note that it happened when the App Engine is already associated with the project_id.

I am wondering what is the best way to debug and test the datastore code in Python.

Upvotes: 2

Views: 296

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39814

For #1 the datastore emulator exacerbates the effects of eventual consistency for a certain fraction of the operations. From gcloud beta emulators datastore start:

--consistency=CONSISTENCY; default="0.9"

Fraction of datastore operations that should succeed.

Upvotes: 2

Related Questions