mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 22:14:55 -04:00
Fix client reader sharding tests (#7853)
* Fix client reader sharding tests * Newsfile * Fix typing * Update changelog.d/7853.misc Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> * Move mocking of http_client to tests Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
This commit is contained in:
parent
b11450dedc
commit
f13061d515
7 changed files with 302 additions and 176 deletions
|
@ -237,6 +237,7 @@ class ThreadedMemoryReactorClock(MemoryReactorClock):
|
|||
def __init__(self):
|
||||
self.threadpool = ThreadPool(self)
|
||||
|
||||
self._tcp_callbacks = {}
|
||||
self._udp = []
|
||||
lookups = self.lookups = {}
|
||||
|
||||
|
@ -268,6 +269,29 @@ class ThreadedMemoryReactorClock(MemoryReactorClock):
|
|||
def getThreadPool(self):
|
||||
return self.threadpool
|
||||
|
||||
def add_tcp_client_callback(self, host, port, callback):
|
||||
"""Add a callback that will be invoked when we receive a connection
|
||||
attempt to the given IP/port using `connectTCP`.
|
||||
|
||||
Note that the callback gets run before we return the connection to the
|
||||
client, which means callbacks cannot block while waiting for writes.
|
||||
"""
|
||||
self._tcp_callbacks[(host, port)] = callback
|
||||
|
||||
def connectTCP(self, host, port, factory, timeout=30, bindAddress=None):
|
||||
"""Fake L{IReactorTCP.connectTCP}.
|
||||
"""
|
||||
|
||||
conn = super().connectTCP(
|
||||
host, port, factory, timeout=timeout, bindAddress=None
|
||||
)
|
||||
|
||||
callback = self._tcp_callbacks.get((host, port))
|
||||
if callback:
|
||||
callback()
|
||||
|
||||
return conn
|
||||
|
||||
|
||||
class ThreadPool:
|
||||
"""
|
||||
|
@ -486,7 +510,7 @@ class FakeTransport(object):
|
|||
try:
|
||||
self.other.dataReceived(to_write)
|
||||
except Exception as e:
|
||||
logger.warning("Exception writing to protocol: %s", e)
|
||||
logger.exception("Exception writing to protocol: %s", e)
|
||||
return
|
||||
|
||||
self.buffer = self.buffer[len(to_write) :]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue