【问题标题】:Gikngo Tests hang during goapp testsGinkgo 测试在 goapp 测试期间挂起
【发布时间】:2017-05-06 05:59:06
【问题描述】:

我正在尝试使用Gikngo 为appengine 编写一些测试。

我的测试设置如下:

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 测试?

【问题讨论】:

    标签: go google-app-engine-go ginkgo


    【解决方案1】:

    事实证明,Ginkgo 或 Golang 与此无关。每秒可以从 dev_appserver.py 读取的字段数似乎有一些限制。 (我怀疑它可能与 dev_appserver 内部使用的数据库 SQLite 有关)。

    以下代码指出问题:

    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 次操作限制的帮助将不胜感激。我能想到的一种技术是人为地注入延迟。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 2014-04-15
      • 2013-04-12
      相关资源
      最近更新 更多