|
6 | 6 | import tempfile |
7 | 7 | import logging.config |
8 | 8 |
|
9 | | -from testgres import get_new_node, stop_all |
| 9 | +from testgres import get_new_node, stop_all, get_config |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class SimpleTest(unittest.TestCase): |
@@ -41,15 +41,21 @@ def test_backup_and_replication(self): |
41 | 41 | self.assertEqual(len(res), 1) |
42 | 42 | self.assertEqual(res[0], (1, 2)) |
43 | 43 |
|
| 44 | + # Prepare the query which would check whether record reached replica |
| 45 | + # (It is slightly different for Postgres 9.6 and Postgres 10+) |
| 46 | + if get_config()['VERSION_NUM'] >= 1000000: |
| 47 | + wait_lsn = 'SELECT pg_current_wal_lsn() <= replay_lsn ' \ |
| 48 | + 'FROM pg_stat_replication WHERE application_name = \'%s\'' \ |
| 49 | + % replica.name |
| 50 | + else: |
| 51 | + wait_lsn = 'SELECT pg_current_xlog_location() <= replay_location '\ |
| 52 | + 'FROM pg_stat_replication WHERE application_name = \'%s\'' \ |
| 53 | + % replica.name |
| 54 | + |
44 | 55 | # Insert into master node |
45 | 56 | node.psql('postgres', 'insert into abc values (3, 4)') |
46 | 57 | # Wait until data syncronizes |
47 | | - node.poll_query_until( |
48 | | - 'postgres', |
49 | | - 'SELECT pg_current_xlog_location() <= replay_location ' |
50 | | - 'FROM pg_stat_replication WHERE application_name = \'%s\'' |
51 | | - % replica.name) |
52 | | - # time.sleep(0.5) |
| 58 | + node.poll_query_until('postgres', wait_lsn) |
53 | 59 | # Check that this record was exported to replica |
54 | 60 | res = replica.execute('postgres', 'select * from abc') |
55 | 61 | self.assertEqual(len(res), 2) |
@@ -83,7 +89,7 @@ def test_users(self): |
83 | 89 | self.assertEqual(value, six.b('1\n')) |
84 | 90 |
|
85 | 91 | def test_logging(self): |
86 | | - regex = re.compile('\w+:\s{1}LOG:.*') |
| 92 | + regex = re.compile('.+?LOG:.*') |
87 | 93 | logfile = tempfile.NamedTemporaryFile('w', delete=True) |
88 | 94 |
|
89 | 95 | log_conf = { |
|
0 commit comments