Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit d7984d1

Browse files
committed
FIX TESTS VIA HACK HACK HACK ALERT
1 parent e0fdbf6 commit d7984d1

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

tests/replication/tcp/streams/_base.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from mock import Mock
1717

18+
from synapse.app.generic_worker import GenericWorkerServer
19+
from synapse.replication.tcp.client import ReplicationDataHandler
1820
from synapse.replication.tcp.handler import ReplicationCommandHandler
1921
from synapse.replication.tcp.protocol import ClientReplicationStreamProtocol
2022
from synapse.replication.tcp.resource import ReplicationStreamProtocolFactory
@@ -26,18 +28,34 @@
2628
class BaseStreamTestCase(unittest.HomeserverTestCase):
2729
"""Base class for tests of the replication streams"""
2830

29-
def make_homeserver(self, reactor, clock):
30-
self.test_handler = Mock(wraps=TestReplicationDataHandler())
31-
return self.setup_test_homeserver(replication_data_handler=self.test_handler)
32-
3331
def prepare(self, reactor, clock, hs):
3432
# build a replication server
3533
server_factory = ReplicationStreamProtocolFactory(hs)
3634
self.streamer = hs.get_replication_streamer()
3735
self.server = server_factory.buildProtocol(None)
3836

39-
repl_handler = ReplicationCommandHandler(hs)
40-
repl_handler.handler = self.test_handler
37+
# Make a new HomeServer object for the worker
38+
config = self.default_config()
39+
config["worker_app"] = "synapse.app.generic_worker"
40+
41+
self.worker_hs = self.setup_test_homeserver(
42+
http_client=None,
43+
homeserverToUse=GenericWorkerServer,
44+
config=config,
45+
reactor=self.reactor,
46+
)
47+
48+
self.test_handler = Mock(
49+
wraps=TestReplicationDataHandler(self.worker_hs.get_datastore())
50+
)
51+
self.worker_hs.replication_data_handler = self.test_handler
52+
53+
# Since we use sqlite in memory databases we need to make sure the
54+
# databases objects are the same.
55+
self.worker_hs.get_datastore().db = hs.get_datastore().db
56+
57+
repl_handler = ReplicationCommandHandler(self.worker_hs)
58+
4159
self.client = ClientReplicationStreamProtocol(
4260
hs, "client", "test", clock, repl_handler,
4361
)
@@ -75,16 +93,15 @@ def replicate(self):
7593
self.pump(0.1)
7694

7795

78-
class TestReplicationDataHandler:
96+
class TestReplicationDataHandler(ReplicationDataHandler):
7997
"""Drop-in for ReplicationDataHandler which just collects RDATA rows"""
8098

81-
def __init__(self):
99+
def __init__(self, hs):
100+
super().__init__(hs)
82101
self.streams = set()
83102
self._received_rdata_rows = []
84103

85104
async def on_rdata(self, stream_name, token, rows):
105+
await super().on_rdata(stream_name, token, rows)
86106
for r in rows:
87107
self._received_rdata_rows.append((stream_name, token, r))
88-
89-
async def on_position(self, stream_name, token):
90-
pass

tests/replication/tcp/streams/test_receipts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def test_receipt(self):
2424
self.reconnect()
2525

2626
# make the client subscribe to the receipts stream
27-
self.test_handler.streams.add("receipts")
2827

2928
# tell the master to send a new receipt
3029
self.get_success(

0 commit comments

Comments
 (0)