Skip to content

Commit a58e3a0

Browse files
Testing database sequence issues in tests fixed
1 parent cf7440b commit a58e3a0

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

test/compare.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ describe('Database.on', () => {
111111

112112
describe('Database.run', () => {
113113
it('sqlite3: insert with plain sql', done => {
114-
const testingFile = createTestDatabaseFile()
115-
116114
// https://github.com/TryGhost/node-sqlite3/wiki/API#runsql--param---callback
117115
function onInsert(error: Error, results: any) {
118116
expect(error).toBeNull()
@@ -127,12 +125,11 @@ describe('Database.run', () => {
127125
done()
128126
}
129127

128+
const testingFile = createTestDatabaseFile()
130129
testingFile.run(INSERT_SQL, onInsert)
131130
})
132131

133132
it('sqlitecloud: insert with plain sql', done => {
134-
const testingCloud = getTestingDatabase()
135-
136133
// https://github.com/TryGhost/node-sqlite3/wiki/API#runsql--param---callback
137134
function onInsert(error: Error, results: any) {
138135
expect(error).toBeNull()
@@ -150,8 +147,10 @@ describe('Database.run', () => {
150147
testingCloud.close()
151148
done()
152149
}
153-
154-
testingCloud.run(INSERT_SQL, onInsert)
150+
const testingCloud = getTestingDatabase(error => {
151+
expect(error).toBeNull()
152+
testingCloud.run(INSERT_SQL, onInsert)
153+
})
155154
})
156155

157156
// end run

test/database.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { SQLiteCloudRowset, SQLiteCloudRow, SQLiteCloudError } from '../src/index'
66
import { getTestingDatabase, getTestingDatabaseAsync, getChinookDatabase, removeDatabase, removeDatabaseAsync, LONG_TIMEOUT } from './shared'
77
import { RowCountCallback } from '../src/drivers/types'
8+
import e from 'express'
89

910
//
1011
// utility methods to setup and destroy temporary test databases
@@ -37,8 +38,10 @@ describe('Database.run', () => {
3738
})
3839
}
3940

40-
const database = getTestingDatabase()
41-
database.run(updateSql, plainCallbackNotALambda)
41+
const database = getTestingDatabase(error => {
42+
expect(error).toBeNull()
43+
database.run(updateSql, plainCallbackNotALambda)
44+
})
4245
},
4346
LONG_TIMEOUT
4447
)
@@ -84,8 +87,10 @@ describe('Database.run', () => {
8487
})
8588
}
8689

87-
const database = getTestingDatabase()
88-
database.run(insertSql, plainCallbackNotALambdaOne)
90+
const database = getTestingDatabase(error => {
91+
expect(error).toBeNull()
92+
database.run(insertSql, plainCallbackNotALambdaOne)
93+
})
8994
},
9095
LONG_TIMEOUT
9196
)

test/shared.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { SQLiteCloudWebsocketConnection } from '../src/drivers/connection-ws'
1313

1414
import * as dotenv from 'dotenv'
1515
import { SQLiteCloudConnection, SQLiteCloudRowset } from '../src'
16+
import e from 'express'
1617
dotenv.config()
1718

1819
export const LONG_TIMEOUT = 1 * 60 * 1000 // 1 minute
@@ -24,7 +25,7 @@ export const WARN_SPEED_MS = 500
2425
export const EXPECT_SPEED_MS = 6 * 1000
2526

2627
/** Number of times or size of stress (when repeated in sequence) */
27-
export const SEQUENCE_TEST_SIZE = 75
28+
export const SEQUENCE_TEST_SIZE = 150
2829
/** Concurrency size for multiple connection tests */
2930
export const SIMULTANEOUS_TEST_SIZE = 150
3031

@@ -160,9 +161,23 @@ export function getTestingConfig(url = TESTING_DATABASE_URL): SQLiteCloudConfig
160161

161162
export function getTestingDatabase(callback?: ResultsCallback): Database {
162163
const testingConfig = getTestingConfig()
163-
const database = new Database(testingConfig)
164+
const database = new Database(testingConfig, error => {
165+
if (error) {
166+
console.error(`getTestingDatabase - connection error: ${error}`)
167+
callback?.call(database, error)
168+
}
169+
database.run(TESTING_SQL, (error: SQLiteCloudError, results: SQLiteCloudRowset) => {
170+
if (error) {
171+
console.error(`getTestingDatabase - setup error: ${error}`)
172+
callback?.call(database, error)
173+
}
174+
expect(results).toBeDefined()
175+
expect(results[0][42]).toBe(42)
176+
callback?.call(database, null)
177+
})
178+
})
179+
164180
// database.verbose()
165-
database.exec(TESTING_SQL, callback)
166181
return database
167182
}
168183

0 commit comments

Comments
 (0)