Skip to content

Commit c46f2b8

Browse files
committed
Add random name suffix to SQL Server test tables
Multiple test functions create tables with names from testTableNameTestData, which can cause flaky failures when running them concurrently. Adding these random suffixes should make sure the table names never collide.
1 parent e0809f9 commit c46f2b8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

plugin/trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/TestSqlServerConnectorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private void testInsertWriteBulkinessWithTimestamps(String timestampType)
178178
public void testCreateAndDropTableWithSpecialCharacterName()
179179
{
180180
for (String tableName : testTableNameTestData()) {
181+
tableName = addNameSuffix(tableName);
181182
String tableNameInSql = "\"" + tableName.replace("\"", "\"\"") + "\"";
182183
// Until https://github.com/trinodb/trino/issues/17 the table name is effectively lowercase
183184
tableName = tableName.toLowerCase(ENGLISH);
@@ -215,6 +216,7 @@ public void testRenameColumnNameAdditionalTests()
215216
public void testRenameFromToTableWithSpecialCharacterName()
216217
{
217218
for (String tableName : testTableNameTestData()) {
219+
tableName = addNameSuffix(tableName);
218220
String tableNameInSql = "\"" + tableName.replace("\"", "\"\"") + "\"";
219221
String sourceTableName = "test_rename_source_" + randomNameSuffix();
220222
assertUpdate("CREATE TABLE " + sourceTableName + " AS SELECT 123 x", 1);
@@ -276,4 +278,14 @@ private List<String> testTableNameTestData()
276278
.add("close]bracket")
277279
.build();
278280
}
281+
282+
/**
283+
* Returns a new name with a random suffix which maintains the shape of the name.
284+
*
285+
* <p>In particular, the suffix is added before any trailing spaces.
286+
*/
287+
private static String addNameSuffix(String name)
288+
{
289+
return name.replaceFirst("(\\s*)$", randomNameSuffix() + "$1");
290+
}
279291
}

0 commit comments

Comments
 (0)