summary refs log tree commit diff
path: root/tests/server.py
diff options
context:
space:
mode:
authorAmber Brown <hawkowl@atleastfornow.net>2019-08-28 21:18:53 +1000
committerGitHub <noreply@github.com>2019-08-28 21:18:53 +1000
commit7dc398586c2156a456d9526ac0e42c1fec9f8143 (patch)
treee5a21464decddbf9798495a351ddb3dbe6e250e4 /tests/server.py
parentFix a cache-invalidation bug for worker-based deployments (#5920) (diff)
downloadsynapse-7dc398586c2156a456d9526ac0e42c1fec9f8143.tar.xz
Implement a structured logging output system. (#5680)
Diffstat (limited to 'tests/server.py')
-rw-r--r--tests/server.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/server.py b/tests/server.py
index e573c4e4c5..c8269619b1 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -11,9 +11,13 @@ from twisted.internet import address, threads, udp
 from twisted.internet._resolver import SimpleResolverComplexifier
 from twisted.internet.defer import Deferred, fail, succeed
 from twisted.internet.error import DNSLookupError
-from twisted.internet.interfaces import IReactorPluggableNameResolver, IResolverSimple
+from twisted.internet.interfaces import (
+    IReactorPluggableNameResolver,
+    IReactorTCP,
+    IResolverSimple,
+)
 from twisted.python.failure import Failure
-from twisted.test.proto_helpers import MemoryReactorClock
+from twisted.test.proto_helpers import AccumulatingProtocol, MemoryReactorClock
 from twisted.web.http import unquote
 from twisted.web.http_headers import Headers
 
@@ -465,3 +469,22 @@ class FakeTransport(object):
         self.buffer = self.buffer[len(to_write) :]
         if self.buffer and self.autoflush:
             self._reactor.callLater(0.0, self.flush)
+
+
+def connect_client(reactor: IReactorTCP, client_id: int) -> AccumulatingProtocol:
+    """
+    Connect a client to a fake TCP transport.
+
+    Args:
+        reactor
+        factory: The connecting factory to build.
+    """
+    factory = reactor.tcpClients[client_id][2]
+    client = factory.buildProtocol(None)
+    server = AccumulatingProtocol()
+    server.makeConnection(FakeTransport(client, reactor))
+    client.makeConnection(FakeTransport(server, reactor))
+
+    reactor.tcpClients.pop(client_id)
+
+    return client, server