Skip to content

Commit 8c23f1d

Browse files
committed
add replicate() method to PostgresNode
1 parent 259c27c commit 8c23f1d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

testgres/testgres.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,19 @@ def backup(self, username=None, xlog_method=DEFAULT_XLOG_METHOD):
872872
username=username,
873873
xlog_method=xlog_method)
874874

875+
def replicate(self, name, username=None, xlog_method=DEFAULT_XLOG_METHOD):
876+
"""
877+
Create a replica of this node.
878+
879+
Args:
880+
name: replica's name (str).
881+
username: database user name (str).
882+
xlog_method: a method for collecting the logs ('fetch' | 'stream').
883+
"""
884+
885+
return self.backup(username=username,
886+
xlog_method=xlog_method).spawn_replica(name)
887+
875888
def pgbench_init(self, dbname='postgres', scale=1, options=[]):
876889
"""
877890
Prepare database for pgbench (create tables etc).

tests/test_simple.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ def test_backup_and_replication(self):
246246
res = replica.execute('postgres', 'select * from abc')
247247
self.assertListEqual(res, [(1, 2), (3, 4)])
248248

249+
def test_replicate(self):
250+
with get_new_node('node') as node:
251+
node.init(allow_streaming=True).start()
252+
253+
with node.replicate(name='replica') as replica:
254+
res = replica.start().execute('postgres', 'select 1')
255+
self.assertListEqual(res, [(1, )])
256+
249257
def test_dump(self):
250258
with get_new_node('node1') as node1:
251259
node1.init().start()

0 commit comments

Comments
 (0)