Reputation: 2016
I have an AppEngine app written in Go, and I'm trying to improve my tests.
Part of the tests that I need to run are a series of create, update, delete queries on the same object. However given that the datastore is eventually consistent (these aren't child objects), I am currently stuck using a time.Sleep(time.Second * 5)
to give the simulated datastore in the SDK enough time for consistency to propagate.
This results in tests that take a long time to run. How can I force something more like strong consistency for tests without rewriting my code to use ancestor queries?
Upvotes: 6
Views: 455
Reputation: 2016
It's been a while, but the method that I found that works well is to call the context as follows:
c, err := aetest.NewContext(&aetest.Options{StronglyConsistentDatastore: true})
Upvotes: 2
Reputation: 12986
Have a look at the dev_server arguments. You will see there is an option for setting the consistency policy.
--datastore_consistency_policy {consistent,random,time}
the policy to apply when deciding whether a datastore
write should appear in global queries (default: time)
Notice the default is time
, you want consistent
Upvotes: 5