Skip to content

Commit dfcbf70

Browse files
Add unique id to test database name
1 parent c69ba97 commit dfcbf70

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

test/connection.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getChinookConnection,
1414
WARN_SPEED_MS,
1515
EXPECT_SPEED_MS,
16-
SELF_SIGNED_CERTIFICATE,
1716
clearTestingDatabasesAsync
1817
} from './shared'
1918

@@ -304,7 +303,7 @@ describe('connection', () => {
304303

305304
it('should apply short timeout', done => {
306305
// this operation sends 150 packets and cannot complete in 200ms
307-
const database = getChinookConnection(undefined, { timeout: 200 })
306+
const database = getChinookConnection(undefined, { timeout: 2 })
308307
database.sendCommands('TEST ROWSET_CHUNK', (error, results) => {
309308
expect(error).toBeInstanceOf(SQLiteCloudError)
310309
expect((error as any).message).toBe('Request timed out')

test/shared.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,22 @@ export function getTestingConfig(url = TESTING_DATABASE_URL): SQLiteCloudConfig
118118

119119
// create a unique id for this test run based on current time with
120120
// enough precision to avoid duplicate ids and be human readable
121-
const id = new Date()
122-
.toISOString()
123-
.replace(/-|:|T|Z|\./g, '')
124-
.slice(0, -1)
121+
function generateRandomId(length: number): string {
122+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
123+
let randomId = ''
124+
for (let i = 0; i < length; i++) {
125+
const randomIndex = Math.floor(Math.random() * characters.length)
126+
randomId += characters.charAt(randomIndex)
127+
}
128+
return randomId
129+
}
130+
const id =
131+
new Date()
132+
.toISOString()
133+
.replace(/-|:|T|Z|\./g, '')
134+
.slice(0, -1) +
135+
'-' +
136+
generateRandomId(4)
125137

126138
testingConfig.createDatabase = true
127139
testingConfig.database = testingConfig.database?.replace('.db', `-${id}.db`)
@@ -185,8 +197,10 @@ export function removeDatabase(database: Database, callback?: ResultsCallback) {
185197
export async function removeDatabaseAsync(database: Database) {
186198
const databaseName = database.getConfiguration().database
187199
if (databaseName) {
188-
const result = await database.sql`UNUSE DATABASE; REMOVE DATABASE ${databaseName};`
189-
console.assert(result)
200+
const result1 = await database.sql`UNUSE DATABASE;`
201+
console.assert(result1)
202+
const result2 = await database.sql`REMOVE DATABASE ${databaseName};`
203+
console.assert(result2)
190204
}
191205
database.close()
192206
}

0 commit comments

Comments
 (0)