def testSlaveWaitAndStop(self):
        "Test the slave_wait_and_stop function"

        slave = self.slaves[0]
        master = self.master

        slave.sql("STOP SLAVE")
        pos1 = fetch_master_position(master)
        change_master(slave, master, pos1)
        slave.sql("START SLAVE")

        master.sql("DROP TABLE IF EXISTS t1", db="test")
        master.sql("CREATE TABLE t1 (a INT)", db="test")
        master.sql("INSERT INTO t1 VALUES (1),(2)", db="test")
        pos2 = fetch_master_position(master)
        master.sql("INSERT INTO t1 VALUES (3),(4)", db="test")
        pos3 = fetch_master_position(master)
        slave_wait_and_stop(slave, pos2)
        pos4 = fetch_slave_position(slave)
        self.assertEqual(pos2, pos4)
        row = slave.sql("SELECT COUNT(*) AS count FROM t1", db="test")
        self.assertEqual(row['count'], 2)
        slave.sql("START SLAVE")
        slave_wait_and_stop(slave, pos3)
        row = slave.sql("SELECT COUNT(*) AS count FROM t1", db="test")
        self.assertEqual(row['count'], 4)
 def testGetSlavePosition(self):
     "Fetching slave positions from the slaves and checking format"
     for slave in self.slaves:
         try:
             position = fetch_slave_position(slave)
             self.assertTrue(_POS_CRE.match(str(position)),
                             "Incorrect position '%s'" % (str(position)))
         except NotSlaveError:
             pass
    def testSlaveWaitForPos(self):
        "Test the slave_wait_for_pos function"

        slave = self.slaves[0]
        master = self.master

        slave.sql("STOP SLAVE")
        pos1 = fetch_master_position(master)
        change_master(slave, master, pos1)
        slave.sql("START SLAVE")

        master.sql("DROP TABLE IF EXISTS t1", db="test")
        master.sql("CREATE TABLE t1 (a INT)", db="test")
        master.sql("INSERT INTO t1 VALUES (1),(2)", db="test")
        pos2 = fetch_master_position(master)
        slave_wait_for_pos(slave, pos2)
        pos3 = fetch_slave_position(slave)
        self.assert_(pos3 >= pos2)