在将来完成之前,NATS整合测试事件循环已停止

时间:2020-07-07 12:10:58

标签: python integration-testing python-asyncio nats.io

我已经为消费者写了一篇有关nat的文章。那么我想为此编写一个整合性信息。我从测试中所做的是:-

  1. 启动nats服务器。
  2. 开始消费
  3. 发布消息。
  4. 从消费者那里收到消息。
  5. 还从消费者那里得到了测试(发布者)的肯定。

但是测试表明事件在将来完成之前就已停止。

我没有输入完整的代码。如果有人需要找出答案。我可以给。


class ConsumerTest(SingleServerTestCase):
  @async_test
  async def test_new_style_request(self):
      nc = NATS()
      payload = b'image uploaded from mobile'
      ack = 'Reply:ACK'
      arguments = {
          "creds": [],
          "servers": "127.0.0.1",
          "subject": config.NAT_CONF["message_subject"],
          "queue": config.NAT_CONF["queue_group_name"],
          "loop": self.loop
      }

      await nc.connect(io_loop=self.loop)

      from app.nats_package.temp import run, run_subscriber
      # self.loop.create_task(run(self.loop, nc, arguments))
      try:
          await run(self.loop, nc, arguments)
      except:
          print("exception khaise re")
      # run_subscriber()

      try:

          response = await nc.request(arguments["subject"], payload, timeout=3)
          print("PAISI", response.data)

      except ErrTimeout:
          print("Request timed out")
      # await asyncio.sleep(1, loop=self.loop)

      await nc.close()
def async_test(test_case_fun, timeout=5):
    @wraps(test_case_fun)
    def wrapper(test_case, *args, **kw):
        return test_case.loop.run_until_complete(
            asyncio.wait_for(
                test_case_fun(test_case, *args, **kw),
                timeout,
                loop=test_case.loop
            )
        )
  return wrapper

    
FAILED (errors=1)

Error
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
    yield
  File "/usr/lib/python3.8/unittest/case.py", line 676, in run
    self._callTestMethod(testMethod)
  File "/usr/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
    method()
  File "/media/sazzad/softwares/sazzad_personal/sil_ml_backend/tests/integration_tests/utils.py", line 441, in wrapper
    return test_case.loop.run_until_complete(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 614, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.

   

0 个答案:

没有答案