我正在尝试使用 Gikngo为应用引擎编写一些测试。
我的测试设置如下:
suite_test.go:
BeforeSuite() {
inst, err = aetest.NewInstance(options)
if err != nil {
Fail(fmt.Sprintf("%s", err))
}
}
var(
req *http.Request
ctx context.Context
)
BeforeEach() {
req = inst.NewRequest()
ctx = appengine.NewContext(req)
// Clean up local datastore using the context.
}
validation_test.go
Describe("Some Test", func() {
It("ValidateFoo", func() {
// Access ctx here
})
...
It("ValidateBar", func() {
// Access ctx here.
})
})
我看到我们的测试一直因类型错误而挂起:
Expected success, but got an error:
<*url.Error | 0xc8210570b0>: {
Op: "Post",
URL: "http://localhost:59072",
Err: {s: "EOF"},
}
Post http://localhost:59072: EOF
这似乎表明 API 服务器已无法访问。然而,测试输出似乎并没有表明这一点。
我们可以通过哪些方式调试 goapp 测试?
最佳答案
事实证明,Ginkgo 或 Golang 与此无关。每秒可以从 dev_appserver.py 读取的字段数似乎有一些限制。 (我怀疑它可能与 SQLite 有关,它是 dev_appserver 内部使用的数据库)。
下面的代码指出了问题:
package preorder
import (
"fmt"
"testing"
"google.golang.org/appengine"
"google.golang.org/appengine/aetest"
"google.golang.org/appengine/datastore"
)
func TestLoad(t *testing.T) {
opts := aetest.Options{StronglyConsistentDatastore: true}
inst, _ := aetest.NewInstance(&opts)
defer inst.Close()
for i := 0; i < 10000; i++ {
req, _ := inst.NewRequest("GET", "/", nil)
ctx := appengine.NewContext(req)
k := datastore.NewKey(ctx, ENTITY_NAME, "", 12345, nil)
var entity Entity
datastore.Get(ctx, k, &entity)
fmt.Println("Iteration Count: ", i)
ctx.Done()
}
}
如果您能提供有关如何解决 240 次操作限制的任何帮助,我们将不胜感激。我能想到的一种技术是人为地注入(inject)延迟。
关于go - Ginkgo 测试在 goapp 测试期间挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43817251/