mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 08:24:55 -04:00
type-hint HomeserverTestcase.setup_test_homeserver
(#10961)
* type-hint `HomeserverTestcase.setup_test_homeserver` For better IDE completion. A small drive-by.
This commit is contained in:
parent
7e440520c9
commit
e46ac85d67
4 changed files with 21 additions and 9 deletions
|
@ -70,8 +70,16 @@ class BaseStreamTestCase(unittest.HomeserverTestCase):
|
|||
# databases objects are the same.
|
||||
self.worker_hs.get_datastore().db_pool = hs.get_datastore().db_pool
|
||||
|
||||
# Normally we'd pass in the handler to `setup_test_homeserver`, which would
|
||||
# eventually hit "Install @cache_in_self attributes" in tests/utils.py.
|
||||
# Unfortunately our handler wants a reference to the homeserver. That leaves
|
||||
# us with a chicken-and-egg problem.
|
||||
# We can workaround this: create the homeserver first, create the handler
|
||||
# and bodge it in after the fact. The bodging requires us to know the
|
||||
# dirty details of how `cache_in_self` works. We politely ask mypy to
|
||||
# ignore our dirty dealings.
|
||||
self.test_handler = self._build_replication_data_handler()
|
||||
self.worker_hs._replication_data_handler = self.test_handler
|
||||
self.worker_hs._replication_data_handler = self.test_handler # type: ignore[attr-defined]
|
||||
|
||||
repl_handler = ReplicationCommandHandler(self.worker_hs)
|
||||
self.client = ClientReplicationStreamProtocol(
|
||||
|
@ -315,12 +323,15 @@ class BaseMultiWorkerStreamTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
)
|
||||
|
||||
# Copy the port into a new, non-Optional variable so mypy knows we're
|
||||
# not going to reset `instance_loc` to `None` under its feet. See
|
||||
# https://mypy.readthedocs.io/en/latest/common_issues.html#narrowing-and-inner-functions
|
||||
port = instance_loc.port
|
||||
|
||||
self.reactor.add_tcp_client_callback(
|
||||
self.reactor.lookups[instance_loc.host],
|
||||
instance_loc.port,
|
||||
lambda: self._handle_http_replication_attempt(
|
||||
worker_hs, instance_loc.port
|
||||
),
|
||||
lambda: self._handle_http_replication_attempt(worker_hs, port),
|
||||
)
|
||||
|
||||
store = worker_hs.get_datastore()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue