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

Commit 363ccb6

Browse files
committed
Fix a bug where only the initial buffer would get sent.
1 parent a32df3b commit 363ccb6

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

synapse/logging/_remote.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ def stopProducing(self):
6161

6262
def resumeProducing(self):
6363
# If we're already producing, nothing to do.
64-
if not self._paused:
65-
return
66-
6764
self._paused = False
6865

6966
# Loop until paused.

tests/logging/test_remote_handler.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
# limitations under the License.
1515
import logging
1616

17+
from twisted.test.proto_helpers import AccumulatingProtocol
18+
1719
from synapse.logging import RemoteHandler
1820

19-
from tests.server import connect_client
21+
from tests.server import FakeTransport
2022
from tests.unittest import DEBUG, HomeserverTestCase
2123

2224

23-
class FakeBeginner:
24-
def beginLoggingTo(self, observers, **kwargs):
25-
self.observers = observers
26-
27-
2825
class StructuredLoggingTestBase:
2926
"""
3027
Test base that registers a cleanup handler to reset the stdlib log handler
@@ -38,6 +35,20 @@ def _cleanup():
3835
self.addCleanup(_cleanup)
3936

4037

38+
def connect_logging_client(reactor, client_id):
39+
# This is essentially tests.server.connect_client, but disabling autoflush on
40+
# the client transport. This is necessary to avoid an infinite loop due to
41+
# sending of data via the logging transport causing additional logs to be
42+
# written.
43+
factory = reactor.tcpClients.pop(client_id)[2]
44+
client = factory.buildProtocol(None)
45+
server = AccumulatingProtocol()
46+
server.makeConnection(FakeTransport(client, reactor))
47+
client.makeConnection(FakeTransport(server, reactor, autoflush=False))
48+
49+
return client, server
50+
51+
4152
class RemoteHandlerTestCase(StructuredLoggingTestBase, HomeserverTestCase):
4253
@DEBUG
4354
def test_log_output(self):
@@ -51,12 +62,10 @@ def test_log_output(self):
5162
logger.info("Hello there, %s!", "wally")
5263

5364
# Trigger the connection
54-
self.pump()
55-
56-
_, server = connect_client(self.reactor, 0)
65+
client, server = connect_logging_client(self.reactor, 0)
5766

5867
# Trigger data being sent
59-
self.pump()
68+
client.transport.flush()
6069

6170
# One log message, with a single trailing newline
6271
logs = server.data.decode("utf8").splitlines()
@@ -89,8 +98,8 @@ def test_log_backpressure_debug(self):
8998
logger.debug("too much debug")
9099

91100
# Allow the reconnection
92-
_, server = connect_client(self.reactor, 0)
93-
self.pump()
101+
client, server = connect_logging_client(self.reactor, 0)
102+
client.transport.flush()
94103

95104
# Only the 7 infos made it through, the debugs were elided
96105
logs = server.data.splitlines()
@@ -124,8 +133,8 @@ def test_log_backpressure_info(self):
124133
logger.debug("too much debug")
125134

126135
# Allow the reconnection
127-
_, server = connect_client(self.reactor, 0)
128-
self.pump()
136+
client, server = connect_logging_client(self.reactor, 0)
137+
client.transport.flush()
129138

130139
# The 10 warnings made it through, the debugs and infos were elided
131140
logs = server.data.splitlines()
@@ -150,8 +159,8 @@ def test_log_backpressure_cut_middle(self):
150159
logger.warning("warn %s" % (i,))
151160

152161
# Allow the reconnection
153-
_, server = connect_client(self.reactor, 0)
154-
self.pump()
162+
client, server = connect_logging_client(self.reactor, 0)
163+
client.transport.flush()
155164

156165
# The first five and last five warnings made it through, the debugs and
157166
# infos were elided

tests/server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,10 @@ def connect_client(reactor: IReactorTCP, client_id: int) -> AccumulatingProtocol
571571
reactor
572572
factory: The connecting factory to build.
573573
"""
574-
factory = reactor.tcpClients[client_id][2]
574+
factory = reactor.tcpClients.pop(client_id)[2]
575575
client = factory.buildProtocol(None)
576576
server = AccumulatingProtocol()
577577
server.makeConnection(FakeTransport(client, reactor))
578578
client.makeConnection(FakeTransport(server, reactor))
579579

580-
reactor.tcpClients.pop(client_id)
581-
582580
return client, server

0 commit comments

Comments
 (0)