|
|
|
|
@ -8,6 +8,7 @@ from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import report_mux
|
|
|
|
|
from reporting_const import REPORT_OPCODES
|
|
|
|
|
from twisted.internet.testing import StringTransport
|
|
|
|
|
from tests.harness.fdmr_monitor_compat import (
|
|
|
|
|
consume_bridge_message,
|
|
|
|
|
consume_config_message,
|
|
|
|
|
@ -191,6 +192,43 @@ class ReportMuxTests(unittest.TestCase):
|
|
|
|
|
with self.assertRaises(argparse.ArgumentTypeError):
|
|
|
|
|
report_mux.parse_backend('0,127.0.0.1,4323')
|
|
|
|
|
|
|
|
|
|
def test_source_accepts_snapshot_above_twisted_default_limit(self):
|
|
|
|
|
mux = report_mux.ReportMuxFactory()
|
|
|
|
|
downstream = _FakeReportClient()
|
|
|
|
|
mux.add_client(downstream)
|
|
|
|
|
source = report_mux.ReportMuxSourceFactory(1, mux).buildProtocol(
|
|
|
|
|
_FakeAddress('127.0.0.1')
|
|
|
|
|
)
|
|
|
|
|
transport = StringTransport()
|
|
|
|
|
source.makeConnection(transport)
|
|
|
|
|
message = _report_message(
|
|
|
|
|
'CONFIG_SND',
|
|
|
|
|
{'SYSTEM-001': {'PEERS': {'large': b'x' * 100_000}}},
|
|
|
|
|
)
|
|
|
|
|
self.assertGreater(len(message), 99_999)
|
|
|
|
|
|
|
|
|
|
source.dataReceived(_netstring(message))
|
|
|
|
|
|
|
|
|
|
self.assertEqual(source.brokenPeer, 0)
|
|
|
|
|
combined = pickle.loads(downstream.messages[-1][1:])
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
combined,
|
|
|
|
|
{'1:SYSTEM-001': {'PEERS': {'large': b'x' * 100_000}}},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_source_rejects_snapshot_above_reporting_limit(self):
|
|
|
|
|
mux = report_mux.ReportMuxFactory()
|
|
|
|
|
source = report_mux.ReportMuxSourceFactory(1, mux).buildProtocol(
|
|
|
|
|
_FakeAddress('127.0.0.1')
|
|
|
|
|
)
|
|
|
|
|
source.makeConnection(StringTransport())
|
|
|
|
|
|
|
|
|
|
source.dataReceived(
|
|
|
|
|
str(report_mux.REPORT_FRAME_MAX_LENGTH + 1).encode('ascii') + b':'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(source.brokenPeer, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PinnedFdmrMonitorCompatibilityTests(unittest.TestCase):
|
|
|
|
|
@classmethod
|
|
|
|
|
@ -305,5 +343,9 @@ def _report_message(opcode, value):
|
|
|
|
|
return REPORT_OPCODES[opcode] + pickle.dumps(value, protocol=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _netstring(message):
|
|
|
|
|
return str(len(message)).encode('ascii') + b':' + message + b','
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|
|