Google app engine GAE推送队列任务不';t在测试中运行,生成孤立的dev_appserver进程

Google app engine GAE推送队列任务不';t在测试中运行,生成孤立的dev_appserver进程,google-app-engine,go,google-cloud-platform,task-queue,Google App Engine,Go,Google Cloud Platform,Task Queue,我注意到,我的任务工作人员从不在测试中运行,而且在测试中,排队/出列逻辑几乎完全解耦,这甚至阻止我验证任务是否正确排队 考虑以下最小示例: app.yaml: runtime: go api_version: go1 handlers: - url: /worker/.* script: _go_app login: admin - url: /.* script: _go_app worker/settle.go(打包工) service/main.go(套餐服务)

我注意到,我的任务工作人员从不在测试中运行,而且在测试中,排队/出列逻辑几乎完全解耦,这甚至阻止我验证任务是否正确排队

考虑以下最小示例:

app.yaml:

runtime: go
api_version: go1

handlers:
 - url: /worker/.*
   script: _go_app
   login: admin
 - url: /.*
   script: _go_app
worker/settle.go(
打包工

service/main.go(
套餐服务

服务/main\u test.go(
套餐服务\u test

请注意,传递给taskqueue.Add(
“/worker/errowpath”
)的路径实际上没有注册的处理程序。乍一看,当我使用
goapp-test-bitwyrm/service-v
进行测试时,这似乎没有引起任何问题,但worker实际上并没有运行。我看到了happy logging语句,TestHandler返回了状态代码200,但是SettleWorker的logging语句没有出现

如果路径正确(即设置为“/工作者/结算”),也会发生同样的情况。因此,我无法编写测试来断言测试是否正确排队

更糟糕的是,出于某种原因,运行此测试还会留下一个孤立的dev_appserver.py进程(无论使用哪个路径)。反复运行这个测试最终会使我的计算机充满孤立的测试进程,这最终会导致通过
goapp test
调用的dev服务器遇到数据库锁定问题,这意味着如果不手动杀死所有孤立的测试进程,我就无法运行我的测试套件。典型堆栈跟踪:

...successful test output...
INFO     2018-05-04 09:02:10,762 stub_util.py:357] Applying all pending transactions and saving the datastore
INFO     2018-05-04 09:02:13,827 stub_util.py:360] Saving search indexes
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 2182, in MainLoop
    self._ProcessQueues()
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 2127, in _ProcessQueues
    response_code = self.task_executor.ExecuteTask(task, queue)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 2059, in ExecuteTask
    '0.1.0.2')
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 776, in add_request
    inst)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 862, in _handle_request
    request_type=request_type)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 818, in _handle_request
    module=self._module_configuration.module_name)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/apiproxy_stub.py", line 186, in WrappedMethod
    return method(self, *args, **kwargs)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/logservice/logservice_stub.py", line 181, in start_request
    host, start_time, method, resource, http_version, module))
OperationalError: database is locked
请注意,在测试之外,这一切似乎都可以正常工作—当我使用Paw和dev_appserver.py在dev中点击这个http处理程序时,正确的路径确实会触发工作进程,而错误的路径会记录403个响应,并进行一系列重试(这两种行为都是您所期望的)


我已经花了足够多的时间来调试它,所以我假设它是
dev_appserver.py
aetest
中的一个实际错误,但我坚信在责怪工具之前,要确保这不是应用程序的错。我是不是做错了什么很明显的事

我本应该参与创建“幻影”进程的工作-结果我只是忘记了在我创建的
aetest.Instance
上调用
Close()

在对实例化进行错误检查后,下面一行为我修复了一些问题:

defer inst.Close()
func TestTestHandler(t *testing.T) {
        inst, err := aetest.NewInstance(nil)
        if err != nil {
                t.Fatal(err.Error())
        }
        req, err := inst.NewRequest("GET", "/", nil)
        if err != nil {
                t.Fatal(err.Error())
        }
        resp := httptest.NewRecorder()
        http.HandlerFunc(service.TestHandler).ServeHTTP(resp, req)
}
...successful test output...
INFO     2018-05-04 09:02:10,762 stub_util.py:357] Applying all pending transactions and saving the datastore
INFO     2018-05-04 09:02:13,827 stub_util.py:360] Saving search indexes
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 2182, in MainLoop
    self._ProcessQueues()
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 2127, in _ProcessQueues
    response_code = self.task_executor.ExecuteTask(task, queue)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 2059, in ExecuteTask
    '0.1.0.2')
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 776, in add_request
    inst)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 862, in _handle_request
    request_type=request_type)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 818, in _handle_request
    module=self._module_configuration.module_name)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/apiproxy_stub.py", line 186, in WrappedMethod
    return method(self, *args, **kwargs)
  File "/Users/ursa/Code/google-cloud-sdk/platform/google_appengine/google/appengine/api/logservice/logservice_stub.py", line 181, in start_request
    host, start_time, method, resource, http_version, module))
OperationalError: database is locked
defer inst.Close()