From 51798893210be73dda9d25d607390be02aba7ae6 Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Wed, 31 Jan 2024 22:20:23 -0500 Subject: [PATCH] Make branch tests compare the original and copied schemas. --- edb/testbase/server.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/edb/testbase/server.py b/edb/testbase/server.py index 6666f29052f..44ddf108f46 100644 --- a/edb/testbase/server.py +++ b/edb/testbase/server.py @@ -1542,12 +1542,14 @@ async def check_branching(self, include_data=False, *, check_method): orig_branch = self.get_database_name() new_branch = f'new_{orig_branch}' + # record the original schema + orig_schema = await self.con.query_single('describe schema as sdl') # connect to a default branch so we can create a new branch - branch_type = 'DATA' if include_data else 'SCHEMA' + branch_type = 'data' if include_data else 'schema' await self.con.execute( - f'CREATE {branch_type} BRANCH {new_branch} ' - f'FROM {orig_branch}' + f'create {branch_type} branch {new_branch} ' + f'from {orig_branch}' ) try: @@ -1559,6 +1561,21 @@ async def check_branching(self, include_data=False, *, check_method): oldcon = self.con self.__class__.con = con2 try: + # We cannot compare the SDL text of the new branch schema to the + # original because the order in which it renders all the + # components is not guaranteed. Instead we will use migrations to + # compare the new branch schema to the original. We expect there + # to be no difference and therefore a new migration to the + # original schema should have the "complete" status right away. + await self.con.execute(f'start migration to {{ {orig_schema} }}') + mig_status = json.loads( + await self.con.query_single_json( + 'describe current migration as json' + ) + ) + self.assertTrue(mig_status.get('complete')) + await self.con.execute('abort migration') + # run the check_method on the copied branch if include_data: await check_method(self)