Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,8 @@ def dump(self,
filename=None,
dbname=None,
username=None,
format=DumpFormat.Plain):
format=DumpFormat.Plain,
options=None):
"""
Dump database into a file using pg_dump.
NOTE: the file is not removed automatically.
Expand All @@ -1402,6 +1403,7 @@ def dump(self,
dbname: database name to connect to.
username: database user name.
format: format argument plain/custom/directory/tar.
options: additional options for pg_dump (list).

Returns:
Path to a file containing dump.
Expand Down Expand Up @@ -1435,6 +1437,10 @@ def tmpfile():
"-F", format.value
] # yapf: disable

# Add additional options if provided
if options:
_params.extend(options)

execute_utility2(self.os_ops, _params, self.utils_log_file)

return filename
Expand Down
25 changes: 25 additions & 0 deletions tests/test_testgres_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,31 @@ def test_dump(self, node_svc: PostgresNodeService):
res = node3.execute(query_select)
assert (res == [(1, ), (2, )])

def test_dump_with_options(self, node_svc: PostgresNodeService):
assert isinstance(node_svc, PostgresNodeService)
query_create = 'create table test_options as select generate_series(1, 5) as val'

with __class__.helper__get_node(node_svc).init().start() as node1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если я все правильно понимаю, то в случае исключения из init или start у нас не произойдет "захват" создаваемого объекта в with и он не будет "зачищен".

Такая же ситуация чуть ниже.

Мне кажется, что это у нас тут какая-та системная проблема в тестах.

Не критично (есть как плюсы так и минусы), но нужно принять во внимание.

node1.execute(query_create)

# Test dump with --schema-only option
with removing(node_svc.os_ops, node1.dump(options=['--schema-only'])) as dump:
with __class__.helper__get_node(node_svc).init().start() as node2:
assert (os.path.isfile(dump))
# restore schema-only dump
node2.restore(filename=dump)

# Check that table exists but has no data
res = node2.execute("SELECT COUNT(*) FROM test_options")
assert (res == [(0,)]) # Table exists but empty

# Verify table structure exists
res = node2.execute("""
SELECT COUNT(*) FROM information_schema.tables
WHERE table_name = 'test_options'
""")
assert (res == [(1,)]) # Table structure exists

def test_pgbench(self, node_svc: PostgresNodeService):
assert isinstance(node_svc, PostgresNodeService)

Expand Down