|
3 | 3 | from typing import Callable
|
4 | 4 | import json
|
5 | 5 |
|
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 |
7 | 7 | from ..docker import DockerManager
|
8 | 8 |
|
9 | 9 | def retry(func: Callable, max_retries: int = 3, retry_delay: int = 2):
|
@@ -414,26 +414,36 @@ def test_quorum_loss(self):
|
414 | 414 | class EnableReplication(ReplicationTest):
|
415 | 415 | AUTOPUBLISH = False
|
416 | 416 |
|
| 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 | + |
417 | 428 | def test_enable_replication(self):
|
418 |
| - """Tests enabling replication on an un-replicated database""" |
| 429 | + """Tests enabling and disabling replication""" |
419 | 430 |
|
420 | 431 | name = random_string()
|
421 | 432 |
|
422 | 433 | 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) |
428 | 435 |
|
429 |
| - self.cluster.wait_counter_value(1, n1, max_attempts=10, delay=10) |
| 436 | + self.add_me_as_admin() |
| 437 | + n = 100 |
430 | 438 |
|
| 439 | + # start un-replicated |
| 440 | + self.run_counter(1, n) |
| 441 | + # enable replication |
431 | 442 | 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