I am following the recommendations on the app engine site for unit testing coding with GAE. I have set the PseudoRandomHRConsistencyPolicy probability to 0% to force the code to account for cases where the data is not yet consistent. The problem is that in my test suite I want to do some data setup (creating and adding data to the datastore) and need a way to force the datastore to flush all the data into a consistent state before I exercise the code under test. (ie. make sure that the datastore will return all global entities I have written the next time I do a query).
Is there any way to do this and if not, how are other people setting up data in their tests suites when开发者_运维技巧 they are using the consistency models?
The key to doing this is noted near the end of the section on HRD testing:
In the local environment, performing a get() of an Entity that belongs to an entity group with an unapplied write will always make the results of the unapplied write visible to subsequent global queries. In production this is not the case.
Simply add some get operations to your tests to get the appropriate records, and they will show up in future queries.
精彩评论