summary refs log tree commit diff
path: root/tests/server.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-01-22 20:28:48 +0000
committerRichard van der Hoff <richard@matrix.org>2019-01-22 20:35:12 +0000
commitd02c4532c068efc54c6abce77e9ec55018b2d444 (patch)
tree1d4ac0f142619b3f841c2a55a33f0792c4861d6a /tests/server.py
parentput resolve_service in an object (diff)
downloadsynapse-d02c4532c068efc54c6abce77e9ec55018b2d444.tar.xz
Add a test for MatrixFederationAgent
Diffstat (limited to '')
-rw-r--r--tests/server.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/server.py b/tests/server.py
index db43fa0db8..3a4aa55645 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -1,4 +1,5 @@
 import json
+import logging
 from io import BytesIO
 
 from six import text_type
@@ -22,6 +23,8 @@ from synapse.util import Clock
 
 from tests.utils import setup_test_homeserver as _sth
 
+logger = logging.getLogger(__name__)
+
 
 class TimedOutException(Exception):
     """
@@ -414,6 +417,11 @@ class FakeTransport(object):
         self.buffer = self.buffer + byt
 
         def _write():
+            if not self.buffer:
+                # nothing to do. Don't write empty buffers: it upsets the
+                # TLSMemoryBIOProtocol
+                return
+
             if getattr(self.other, "transport") is not None:
                 self.other.dataReceived(self.buffer)
                 self.buffer = b""
@@ -421,7 +429,10 @@ class FakeTransport(object):
 
             self._reactor.callLater(0.0, _write)
 
-        _write()
+        # always actually do the write asynchronously. Some protocols (notably the
+        # TLSMemoryBIOProtocol) get very confused if a read comes back while they are
+        # still doing a write. Doing a callLater here breaks the cycle.
+        self._reactor.callLater(0.0, _write)
 
     def writeSequence(self, seq):
         for x in seq: