Skip to content

Commit e529e53

Browse files
committed
Enable and disable replication in test
1 parent 34b3403 commit e529e53

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

smoketests/tests/replication.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Callable
44
import json
55

6-
from .. import COMPOSE_FILE, Smoketest, requires_docker, spacetime, parse_sql_result
6+
from .. import COMPOSE_FILE, Smoketest, random_string, requires_docker, spacetime, parse_sql_result
77
from ..docker import DockerManager
88

99
def retry(func: Callable, max_retries: int = 3, retry_delay: int = 2):
@@ -414,26 +414,36 @@ def test_quorum_loss(self):
414414
class EnableReplication(ReplicationTest):
415415
AUTOPUBLISH = False
416416

417+
def __init__(self, *args, **kwargs):
418+
super().__init__(*args, **kwargs)
419+
420+
self.expected_counter_rows = []
421+
422+
def run_counter(self, id, n = 100):
423+
self.start(id, n)
424+
self.cluster.wait_counter_value(id, n)
425+
self.expected_counter_rows.append({"id": id, "value": n})
426+
self.assertEqual(self.collect_counter_rows(), self.expected_counter_rows)
427+
417428
def test_enable_replication(self):
418-
"""Tests enabling replication on an un-replicated database"""
429+
"""Tests enabling and disabling replication"""
419430

420431
name = random_string()
421432

422433
self.publish_module(name, num_replicas = 1)
423-
leader = self.cluster.wait_for_leader_change(None)
424-
425-
n1 = 1_000
426-
n2 = 100
427-
self.start(1, n1)
434+
self.cluster.wait_for_leader_change(None)
428435

429-
self.cluster.wait_counter_value(1, n1, max_attempts=10, delay=10)
436+
self.add_me_as_admin()
437+
n = 100
430438

439+
# start un-replicated
440+
self.run_counter(1, n)
441+
# enable replication
431442
self.call_control("enable_replication", {"Name": name}, 3)
432-
433-
self.cluster.wait_for_leader_change(leader)
434-
self.start(2, n2)
435-
436-
self.cluster.wait_counter_value(2, n2)
437-
438-
rows = self.collect_counter_rows()
439-
self.assertEqual([{"id": 1, "value": n1}, {"id": 2, "value": n2}], rows)
443+
self.run_counter(2, n)
444+
# disable replication
445+
self.call_control("disable_replication", {"Name": name })
446+
self.run_counter(3, n)
447+
# enable it one more time
448+
self.call_control("enable_replication", {"Name": name}, 3)
449+
self.start(4, n)

0 commit comments

Comments
 (0)