|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -import unittest |
3 | | - |
4 | 2 | import time |
| 3 | +import sys |
| 4 | +if sys.version_info < (2, 7): |
| 5 | + import unittest2 as unittest |
| 6 | +else: |
| 7 | + import unittest |
5 | 8 |
|
6 | 9 | from pymysqlreplication.tests import base |
7 | 10 | from pymysqlreplication import BinLogStreamReader |
@@ -585,6 +588,33 @@ def test_drop_column(self): |
585 | 588 | finally: |
586 | 589 | self.resetBinLog() |
587 | 590 |
|
| 591 | + @unittest.expectedFailure |
| 592 | + def test_alter_column(self): |
| 593 | + self.stream.close() |
| 594 | + self.execute("CREATE TABLE test_alter_column (id INTEGER(11), data VARCHAR(50))") |
| 595 | + self.execute("INSERT INTO test_alter_column VALUES (1, 'A value')") |
| 596 | + self.execute("COMMIT") |
| 597 | + # this is a problem only when column is added in position other than at the end |
| 598 | + self.execute("ALTER TABLE test_alter_column ADD COLUMN another_data VARCHAR(50) AFTER id") |
| 599 | + self.execute("INSERT INTO test_alter_column VALUES (2, 'Another value', 'A value')") |
| 600 | + self.execute("COMMIT") |
| 601 | + |
| 602 | + self.stream = BinLogStreamReader( |
| 603 | + self.database, |
| 604 | + server_id=1024, |
| 605 | + only_events=(WriteRowsEvent,), |
| 606 | + ) |
| 607 | + event = self.stream.fetchone() # insert with two values |
| 608 | + # both of these asserts fail because of issue underlying proble described in issue #118 |
| 609 | + # because it got table schema info after the alter table, it wrongly assumes the second |
| 610 | + # column of the first insert is 'another_data' |
| 611 | + # ER: {'id': 1, 'data': 'A value'} |
| 612 | + # AR: {'id': 1, 'another_data': 'A value'} |
| 613 | + self.assertIn("data", event.rows[0]["values"]) |
| 614 | + self.assertNot("another_data", event.rows[0]["values"]) |
| 615 | + self.assertEqual(event.rows[0]["values"]["data"], 'A value') |
| 616 | + self.stream.fetchone() # insert with three values |
| 617 | + |
588 | 618 |
|
589 | 619 | class TestGtidBinLogStreamReader(base.PyMySQLReplicationTestCase): |
590 | 620 | def setUp(self): |
|
0 commit comments