Skip to content

Commit 1ee7215

Browse files
richvdhphil-flex
authored andcommitted
Another go at fixing one-word commands (matrix-org#7326)
I messed this up last time I tried (matrix-org#7239 / e13c6c7).
1 parent 56f2c3f commit 1ee7215

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

changelog.d/7326.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move catchup of replication streams logic to worker.

synapse/replication/tcp/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def parse_command_from_line(line: str) -> Command:
462462
Line should already be stripped of whitespace and be checked if blank.
463463
"""
464464

465-
idx = line.index(" ")
465+
idx = line.find(" ")
466466
if idx >= 0:
467467
cmd_name = line[:idx]
468468
rest_of_line = line[idx + 1 :]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2020 The Matrix.org Foundation C.I.C.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
from synapse.replication.tcp.commands import (
16+
RdataCommand,
17+
ReplicateCommand,
18+
parse_command_from_line,
19+
)
20+
21+
from tests.unittest import TestCase
22+
23+
24+
class ParseCommandTestCase(TestCase):
25+
def test_parse_one_word_command(self):
26+
line = "REPLICATE"
27+
cmd = parse_command_from_line(line)
28+
self.assertIsInstance(cmd, ReplicateCommand)
29+
30+
def test_parse_rdata(self):
31+
line = 'RDATA events 6287863 ["ev", ["$eventid", "!roomid", "type", null, null, null]]'
32+
cmd = parse_command_from_line(line)
33+
self.assertIsInstance(cmd, RdataCommand)
34+
self.assertEqual(cmd.stream_name, "events")
35+
self.assertEqual(cmd.token, 6287863)
36+
37+
def test_parse_rdata_batch(self):
38+
line = 'RDATA presence batch ["@foo:example.com", "online"]'
39+
cmd = parse_command_from_line(line)
40+
self.assertIsInstance(cmd, RdataCommand)
41+
self.assertEqual(cmd.stream_name, "presence")
42+
self.assertIsNone(cmd.token)

0 commit comments

Comments
 (0)