From ba318444371b7a24dca637fca433bda3e406f060 Mon Sep 17 00:00:00 2001 From: Andrei-Adnan Ismail Date: Thu, 29 Oct 2015 12:13:07 +0200 Subject: [PATCH] #395 First working test: an INSERT done via ProxySQL to the master should be visible in the slaves --- test/replication_topology_awareness_test.py | 35 ++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/test/replication_topology_awareness_test.py b/test/replication_topology_awareness_test.py index 6e93dd937..4561e9e29 100644 --- a/test/replication_topology_awareness_test.py +++ b/test/replication_topology_awareness_test.py @@ -1,6 +1,8 @@ import MySQLdb from MySQLdb import OperationalError from nose.tools import raises +import random +import time from proxysql_base_test import ProxySQLBaseTest @@ -26,10 +28,35 @@ class ReplicationTopologyAwareness(ProxySQLBaseTest): self.run_query_mysql_container(q, 'information_schema', slave_container_id) self.run_query_mysql_container('START SLAVE', 'information_schema', slave_container_id) - def _test_promoting_slave_to_master_correctly_updates_admin_tables(self): + slave_caught_up = False + while not slave_caught_up: + slave_status = self.run_query_mysql_container( + 'SHOW SLAVE STATUS', + 'information_schema', + slave_container_id + ) + slave_caught_up = slave_status[0][44].startswith( + 'Slave has read all relay log') + + def _test_insert_sent_through_proxysql_is_visible_in_slave_servers(self): self._start_replication() - import pdb; pdb.set_trace() - def test_promoting_slave_to_master_correctly_updates_admin_tables(self): - self.run_in_docker_scenarios(self._test_promoting_slave_to_master_correctly_updates_admin_tables, + random_string = ''.join(random.choice(['a', 'b', 'c', 'd', 'e']) for _ in xrange(10)) + q = "INSERT INTO strings(value) VALUES('%s')" % random_string + self.run_query_proxysql(q, "test") + + # Give slaves the time to catch up + time.sleep(5) + + slave_containers = self.get_mysql_containers(hostgroup=1) + for slave_container_id in slave_containers: + q = "SELECT * FROM strings" + rows = self.run_query_mysql_container("SELECT * FROM strings", + "test", + slave_container_id) + self.assertEqual(set([row[0] for row in rows]), + set(['a', 'ab', 'abc', 'abcd', random_string])) + + def test_insert_sent_through_proxysql_is_visible_in_slave_servers(self): + self.run_in_docker_scenarios(self._test_insert_sent_through_proxysql_is_visible_in_slave_servers, scenarios=['5backends-replication']) \ No newline at end of file