在测试期间控制AppEngine数据存储的一致性

huangapple go评论73阅读模式
英文:

Controling eventual AppEngine datastory consistency during testing

问题

我有一个用Go编写的AppEngine应用程序,我正在尝试改进我的测试。

我需要运行一系列在同一对象上进行创建、更新、删除查询的测试。然而,由于数据存储是最终一致性的(这些不是子对象),我目前被迫使用time.Sleep(time.Second * 5)来给SDK中的模拟数据存储足够的时间来传播一致性。

这导致测试运行时间很长。如何在不重写我的代码以使用祖先查询的情况下,强制进行更接近强一致性的测试?

英文:

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?

答案1

得分: 5

请查看dev_server的参数。你会看到有一个选项用于设置一致性策略。

--datastore_consistency_policy {consistent,random,time}
决定数据存储写入是否应该出现在全局查询中的策略(默认值:time)

请注意,默认值是time,你想要的是consistent

英文:

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

答案2

得分: 2

已翻译内容:

已经有一段时间了,但我发现以下方法可以很好地调用上下文:

c, err := aetest.NewContext(&aetest.Options{StronglyConsistentDatastore: true})

英文:

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

huangapple
  • 本文由 发表于 2014年5月13日 07:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/23620366.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定