Skip to content

Commit

Permalink
Fix dump tests after CLI breakage (#7555)
Browse files Browse the repository at this point in the history
edgedb/edgedb-cli#1184 made dump refuse to overwrite files by default,
which broke our dump tests.

We could fix it by passing the flag to allow overwriting to the CLI,
but it seems more natural to make a temp *directory* instead of
overwriting a temp file.
  • Loading branch information
msullivan committed Aug 21, 2024
1 parent 3b73c16 commit 49c6c91
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions edb/testbase/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,12 +1482,13 @@ class StableDumpTestCase(QueryTestCase, CLITestCaseMixin):
PARALLELISM_GRANULARITY = 'suite'

async def check_dump_restore_single_db(self, check_method):
with tempfile.NamedTemporaryFile() as f:
with tempfile.TemporaryDirectory() as f:
fname = os.path.join(f, 'dump')
dbname = edgedb_defines.EDGEDB_SUPERUSER_DB
await asyncio.to_thread(self.run_cli, '-d', dbname, 'dump', f.name)
await asyncio.to_thread(self.run_cli, '-d', dbname, 'dump', fname)
await self.tearDownSingleDB()
await asyncio.to_thread(
self.run_cli, '-d', dbname, 'restore', f.name
self.run_cli, '-d', dbname, 'restore', fname
)

# Cycle the connection to avoid state mismatches
Expand All @@ -1503,15 +1504,16 @@ async def check_dump_restore(self, check_method):
src_dbname = self.get_database_name()
tgt_dbname = f'{src_dbname}_restored'
q_tgt_dbname = qlquote.quote_ident(tgt_dbname)
with tempfile.NamedTemporaryFile() as f:
with tempfile.TemporaryDirectory() as f:
fname = os.path.join(f, 'dump')
await asyncio.to_thread(
self.run_cli, '-d', src_dbname, 'dump', f.name
self.run_cli, '-d', src_dbname, 'dump', fname
)

await self.con.execute(f'CREATE DATABASE {q_tgt_dbname}')
try:
await asyncio.to_thread(
self.run_cli, '-d', tgt_dbname, 'restore', f.name
self.run_cli, '-d', tgt_dbname, 'restore', fname
)
con2 = await self.connect(database=tgt_dbname)
except Exception:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_dump_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ async def test_dump_fuzz_01(self):
dbname = self.get_database_name()
restored_dbname = f'{dbname}_restored'

with tempfile.NamedTemporaryFile() as f:
self.run_cli('-d', dbname, 'dump', f.name)
with tempfile.TemporaryDirectory() as f:
fname = os.path.join(f, 'dump')
self.run_cli('-d', dbname, 'dump', fname)

await self.con.execute(f'CREATE DATABASE {restored_dbname}')
try:
self.run_cli('-d', restored_dbname, 'restore', f.name)
self.run_cli('-d', restored_dbname, 'restore', fname)
con2 = await self.connect(database=restored_dbname)
except Exception:
await tb.drop_db(self.con, restored_dbname)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_server_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,17 +1095,18 @@ async def _test_server_ops_restore_with_schema_signal(self, sd1, sd2):

try:
# Dump and restore should trigger a re-introspection in sd2
with tempfile.NamedTemporaryFile() as f:
with tempfile.TemporaryDirectory() as f:
fname = os.path.join(f, 'dump')
await asyncio.to_thread(
self.run_cli_on_connection, conn_args, "dump", f.name
self.run_cli_on_connection, conn_args, "dump", fname
)
await asyncio.to_thread(
self.run_cli_on_connection,
conn_args,
"-d",
"restore_signal",
"restore",
f.name
fname
)

# The re-introspection has a delay, but should eventually happen
Expand Down

0 comments on commit 49c6c91

Please sign in to comment.