Kaynağa Gözat

Move `wait_until_result` into `FakeChannel` (#8758)

FakeChannel has everything we need, and this more accurately models the real
flow.
tags/v1.24.0rc1
Richard van der Hoff 3 yıl önce
committed by GitHub
ebeveyn
işleme
f125895475
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: 4AEE18F83AFDEB23
3 değiştirilmiş dosya ile 24 ekleme ve 25 silme
  1. +1
    -0
      changelog.d/8758.misc
  2. +3
    -3
      tests/rest/key/v2/test_remote_key_resource.py
  3. +20
    -22
      tests/server.py

+ 1
- 0
changelog.d/8758.misc Dosyayı Görüntüle

@@ -0,0 +1 @@
Refactor test utilities for injecting HTTP requests.

+ 3
- 3
tests/rest/key/v2/test_remote_key_resource.py Dosyayı Görüntüle

@@ -32,7 +32,7 @@ from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.stringutils import random_string

from tests import unittest
from tests.server import FakeChannel, wait_until_result
from tests.server import FakeChannel
from tests.utils import default_config


@@ -94,7 +94,7 @@ class RemoteKeyResourceTestCase(BaseRemoteKeyResourceTestCase):
% (server_name.encode("utf-8"), key_id.encode("utf-8")),
b"1.1",
)
wait_until_result(self.reactor, req)
channel.await_result()
self.assertEqual(channel.code, 200)
resp = channel.json_body
return resp
@@ -190,7 +190,7 @@ class EndToEndPerspectivesTests(BaseRemoteKeyResourceTestCase):
req.requestReceived(
b"POST", path.encode("utf-8"), b"1.1",
)
wait_until_result(self.reactor, req)
channel.await_result()
self.assertEqual(channel.code, 200)
resp = channel.json_body
return resp


+ 20
- 22
tests/server.py Dosyayı Görüntüle

@@ -117,6 +117,25 @@ class FakeChannel:
def transport(self):
return self

def await_result(self, timeout: int = 100) -> None:
"""
Wait until the request is finished.
"""
self._reactor.run()
x = 0

while not self.result.get("done"):
# If there's a producer, tell it to resume producing so we get content
if self._producer:
self._producer.resumeProducing()

x += 1

if x > timeout:
raise TimedOutException("Timed out waiting for request to finish.")

self._reactor.advance(0.1)


class FakeSite:
"""
@@ -225,30 +244,9 @@ def make_request(
return req, channel


def wait_until_result(clock, request, timeout=100):
"""
Wait until the request is finished.
"""
clock.run()
x = 0

while not request.finished:

# If there's a producer, tell it to resume producing so we get content
if request._channel._producer:
request._channel._producer.resumeProducing()

x += 1

if x > timeout:
raise TimedOutException("Timed out waiting for request to finish.")

clock.advance(0.1)


def render(request, resource, clock):
request.render(resource)
wait_until_result(clock, request)
request._channel.await_result()


@implementer(IReactorPluggableNameResolver)


Yükleniyor…
İptal
Kaydet