Skip to content

Commit

Permalink
Fix sporadic failures in HANA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrylov authored and nyalldawson committed Mar 8, 2021
1 parent fe5c761 commit 379fbc8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
44 changes: 26 additions & 18 deletions tests/src/python/test_qgsproviderconnection_base.py
Expand Up @@ -72,6 +72,11 @@ def tearDownClass(cls):
def setUp(self):
QgsSettings().clear()

def getUniqueSchemaName(self, name):
"""This function must return a schema name with unique prefix/postfix,
if the tests are run simultaneously on the same machine by different CI instances"""
return name

def _test_save_load(self, md, uri, configuration):
"""Common tests on connection save and load"""

Expand Down Expand Up @@ -105,42 +110,45 @@ def _test_operations(self, md, conn):
and capabilities & QgsAbstractDatabaseProviderConnection.Schemas
and capabilities & QgsAbstractDatabaseProviderConnection.DropSchema):

myNewSchema = self.getUniqueSchemaName('myNewSchema')
# Start clean
if 'myNewSchema' in conn.schemas():
conn.dropSchema('myNewSchema', True)
if myNewSchema in conn.schemas():
conn.dropSchema(myNewSchema, True)

# Create
conn.createSchema('myNewSchema')
conn.createSchema(myNewSchema)
schemas = conn.schemas()
self.assertTrue('myNewSchema' in schemas)
self.assertTrue(myNewSchema in schemas)

# Create again
with self.assertRaises(QgsProviderConnectionException) as ex:
conn.createSchema('myNewSchema')
conn.createSchema(myNewSchema)

# Test rename
if capabilities & QgsAbstractDatabaseProviderConnection.RenameSchema:
# Rename
conn.renameSchema('myNewSchema', 'myVeryNewSchema')
myVeryNewSchema = self.getUniqueSchemaName('myVeryNewSchema')
conn.renameSchema(myNewSchema, myVeryNewSchema)
schemas = conn.schemas()
self.assertTrue('myVeryNewSchema' in schemas)
self.assertFalse('myNewSchema' in schemas)
conn.renameSchema('myVeryNewSchema', 'myNewSchema')
self.assertTrue(myVeryNewSchema in schemas)
self.assertFalse(myNewSchema in schemas)
conn.renameSchema(myVeryNewSchema, myNewSchema)
schemas = conn.schemas()
self.assertFalse('myVeryNewSchema' in schemas)
self.assertTrue('myNewSchema' in schemas)
self.assertFalse(myVeryNewSchema in schemas)
self.assertTrue(myNewSchema in schemas)

# Drop
conn.dropSchema('myNewSchema')
conn.dropSchema(myNewSchema)
schemas = conn.schemas()
self.assertFalse('myNewSchema' in schemas)
self.assertFalse(myNewSchema in schemas)

# UTF8 schema
conn.createSchema('myUtf8\U0001f604NewSchema')
myUtf8NewSchema = self.getUniqueSchemaName('myUtf8\U0001f604NewSchema')
conn.createSchema(myUtf8NewSchema)
schemas = conn.schemas()
conn.dropSchema('myUtf8\U0001f604NewSchema')
conn.dropSchema(myUtf8NewSchema)
schemas = conn.schemas()
self.assertFalse('myUtf8\U0001f604NewSchema' in schemas)
self.assertFalse(myUtf8NewSchema in schemas)

# Table operations
schema = None
Expand All @@ -149,11 +157,11 @@ def _test_operations(self, md, conn):
and capabilities & QgsAbstractDatabaseProviderConnection.DropVectorTable):

if capabilities & QgsAbstractDatabaseProviderConnection.CreateSchema:
schema = 'myNewSchema'
schema = self.getUniqueSchemaName('myNewSchema')
conn.createSchema(schema)

elif capabilities & QgsAbstractDatabaseProviderConnection.Schemas:
schema = self.defaultSchema
schema = self.getUniqueSchemaName(self.defaultSchema)

# Start clean
if self.myNewTable in self._table_names(conn.tables(schema)):
Expand Down
3 changes: 3 additions & 0 deletions tests/src/python/test_qgsproviderconnection_hana.py
Expand Up @@ -58,6 +58,9 @@ def tearDownClass(cls):
QgsHanaProviderUtils.cleanUp(cls.conn, cls.schemaName)
cls.conn.close()

def getUniqueSchemaName(self, name):
return 'qgis_test_' + QgsHanaProviderUtils.generateSchemaName(self.conn, name)

def createProviderMetadata(self):
return QgsProviderRegistry.instance().providerMetadata(self.providerKey)

Expand Down

0 comments on commit 379fbc8

Please sign in to comment.