Skip to content

Commit b24af26

Browse files
committed
Work around connections not being closed by adding a new database prefix option
1 parent 738f54a commit b24af26

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/sqlancer/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private String formatInteger(long intValue) {
453453
ExecutorService execService = Executors.newFixedThreadPool(options.getNumberConcurrentThreads());
454454
DBMSExecutorFactory<?, ?> executorFactory = nameToProvider.get(jc.getParsedCommand());
455455
for (int i = 0; i < options.getTotalNumberTries(); i++) {
456-
final String databaseName = "database" + i;
456+
final String databaseName = options.getDatabasePrefix() + i;
457457
final long seed;
458458
if (options.getRandomSeed() == -1) {
459459
seed = System.currentTimeMillis() + i;

src/sqlancer/MainOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public class MainOptions {
8888
@Parameter(names = "--constant-cache-size", description = "Specifies the size of the constant cache. This option only takes effect when constant caching is enabled")
8989
private int constantCacheSize = 100; // NOPMD
9090

91+
@Parameter(names = "--database-prefix", description = "The prefix used for each database created")
92+
private String databasePrefix = "database"; // NOPMD
93+
9194
public int getMaxExpressionDepth() {
9295
return maxExpressionDepth;
9396
}
@@ -197,4 +200,8 @@ public boolean isHelp() {
197200
return help;
198201
}
199202

203+
public String getDatabasePrefix() {
204+
return databasePrefix;
205+
}
206+
200207
}

test/sqlancer/dbms/TestPostgres.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public void testPQS() {
2727
assertEquals(0,
2828
Main.executeMain(new String[] { "--random-seed", "0", "--timeout-seconds", TestConfig.SECONDS,
2929
"--num-threads", "4", "--num-queries", TestConfig.NUM_QUERIES, "--random-string-generation",
30-
"ALPHANUMERIC_SPECIALCHAR", "postgres", "--test-collations", "false", "--oracle", "pqs" }));
30+
"ALPHANUMERIC_SPECIALCHAR", "--database-prefix",
31+
"pqsdb" /* Workaround for connections not being closed */, "postgres", "--test-collations",
32+
"false", "--oracle", "pqs" }));
3133
}
3234

3335
}

0 commit comments

Comments
 (0)