@@ -20,8 +20,21 @@ export const LONG_TIMEOUT = 100 * 1000 // 100 seconds
2020export function getChinoookConfig ( ) : SQLiteCloudConfig {
2121 return parseConnectionString ( CHINOOK_DATABASE_URL )
2222}
23+
2324export function getTestingConfig ( ) : SQLiteCloudConfig {
24- return parseConnectionString ( TESTING_DATABASE_URL )
25+ const testingConfig = parseConnectionString ( TESTING_DATABASE_URL )
26+ testingConfig . sqliteMode = true
27+
28+ // create a unique id for this test run based on current time with
29+ // enough precision to avoid duplicate ids and be human readable
30+ const id = new Date ( )
31+ . toISOString ( )
32+ . replace ( / - | : | T | Z | \. / g, '' )
33+ . slice ( 0 , - 1 )
34+
35+ testingConfig . createDatabase = true
36+ testingConfig . database = testingConfig . database ?. replace ( '.db' , `-${ id } .db` )
37+ return testingConfig
2538}
2639
2740export const CHINOOK_FIRST_TRACK = {
@@ -37,24 +50,27 @@ export const CHINOOK_FIRST_TRACK = {
3750}
3851
3952describe ( 'connection' , ( ) => {
40- let connection : SQLiteCloudConnection
53+ let chinook : SQLiteCloudConnection
4154
42- beforeEach ( done => {
55+ beforeAll ( ( ) => {
4356 expect ( CHINOOK_DATABASE_URL ) . toBeDefined ( )
4457 expect ( TESTING_DATABASE_URL ) . toBeDefined ( )
45- connection = new SQLiteCloudConnection ( CHINOOK_DATABASE_URL + '?nonlinearizable=1' , error => {
46- expect ( connection ) . toBeDefined ( )
58+ } )
59+
60+ beforeEach ( done => {
61+ chinook = new SQLiteCloudConnection ( CHINOOK_DATABASE_URL + '?nonlinearizable=1' , error => {
62+ expect ( chinook ) . toBeDefined ( )
4763 done ( )
4864 } )
4965 // connection.verbose()
5066 } )
5167
5268 afterEach ( ( ) => {
53- if ( connection ) {
54- connection . close ( )
69+ if ( chinook ) {
70+ chinook . close ( )
5571 }
5672 // @ts -ignore
57- connection = undefined
73+ chinook = undefined
5874 } )
5975
6076 describe ( 'connect' , ( ) => {
@@ -71,7 +87,7 @@ describe('connection', () => {
7187 expect ( error ) . toBeNull ( )
7288 expect ( conn . connected ) . toBe ( true )
7389
74- connection . sendCommands ( 'TEST STRING' , ( error , results ) => {
90+ chinook . sendCommands ( 'TEST STRING' , ( error , results ) => {
7591 conn . close ( )
7692 expect ( conn . connected ) . toBe ( false )
7793 done ( )
@@ -87,7 +103,7 @@ describe('connection', () => {
87103 expect ( error ) . toBeNull ( )
88104 expect ( conn . connected ) . toBe ( true )
89105
90- connection . sendCommands ( 'TEST STRING' , ( error , results ) => {
106+ chinook . sendCommands ( 'TEST STRING' , ( error , results ) => {
91107 conn . close ( )
92108 expect ( conn . connected ) . toBe ( false )
93109 done ( )
@@ -119,63 +135,63 @@ describe('connection', () => {
119135
120136 describe ( 'send test commands' , ( ) => {
121137 it ( 'should test integer' , done => {
122- connection . sendCommands ( 'TEST INTEGER' , ( error , results ) => {
138+ chinook . sendCommands ( 'TEST INTEGER' , ( error , results ) => {
123139 expect ( error ) . toBeNull ( )
124140 expect ( results ) . toBe ( 123456 )
125141 done ( )
126142 } )
127143 } )
128144
129145 it ( 'should test null' , done => {
130- connection . sendCommands ( 'TEST NULL' , ( error , results ) => {
146+ chinook . sendCommands ( 'TEST NULL' , ( error , results ) => {
131147 expect ( error ) . toBeNull ( )
132148 expect ( results ) . toBeNull ( )
133149 done ( )
134150 } )
135151 } )
136152
137153 it ( 'should test float' , done => {
138- connection . sendCommands ( 'TEST FLOAT' , ( error , results ) => {
154+ chinook . sendCommands ( 'TEST FLOAT' , ( error , results ) => {
139155 expect ( error ) . toBeNull ( )
140156 expect ( results ) . toBe ( 3.1415926 )
141157 done ( )
142158 } )
143159 } )
144160
145161 it ( 'should test string' , done => {
146- connection . sendCommands ( 'TEST STRING' , ( error , results ) => {
162+ chinook . sendCommands ( 'TEST STRING' , ( error , results ) => {
147163 expect ( error ) . toBeNull ( )
148164 expect ( results ) . toBe ( 'Hello World, this is a test string.' )
149165 done ( )
150166 } )
151167 } )
152168
153169 it ( 'should test zero string' , done => {
154- connection . sendCommands ( 'TEST ZERO_STRING' , ( error , results ) => {
170+ chinook . sendCommands ( 'TEST ZERO_STRING' , ( error , results ) => {
155171 expect ( error ) . toBeNull ( )
156172 expect ( results ) . toBe ( 'Hello World, this is a zero-terminated test string.' )
157173 done ( )
158174 } )
159175 } )
160176
161177 it ( 'should test string0' , done => {
162- connection . sendCommands ( 'TEST STRING0' , ( error , results ) => {
178+ chinook . sendCommands ( 'TEST STRING0' , ( error , results ) => {
163179 expect ( error ) . toBeNull ( )
164180 expect ( results ) . toBe ( '' )
165181 done ( )
166182 } )
167183 } )
168184
169185 it ( 'should test command' , done => {
170- connection . sendCommands ( 'TEST COMMAND' , ( error , results ) => {
186+ chinook . sendCommands ( 'TEST COMMAND' , ( error , results ) => {
171187 expect ( error ) . toBeNull ( )
172188 expect ( results ) . toBe ( 'PING' )
173189 done ( )
174190 } )
175191 } )
176192
177193 it ( 'should test json' , done => {
178- connection . sendCommands ( 'TEST JSON' , ( error , results ) => {
194+ chinook . sendCommands ( 'TEST JSON' , ( error , results ) => {
179195 expect ( error ) . toBeNull ( )
180196 expect ( results ) . toEqual ( {
181197 'msg-from' : { class : 'soldier' , name : 'Wixilav' } ,
@@ -193,7 +209,7 @@ describe('connection', () => {
193209 } )
194210
195211 it ( 'should test blob' , done => {
196- connection . sendCommands ( 'TEST BLOB' , ( error , results ) => {
212+ chinook . sendCommands ( 'TEST BLOB' , ( error , results ) => {
197213 expect ( error ) . toBeNull ( )
198214 expect ( typeof results ) . toBe ( 'object' )
199215 expect ( results ) . toBeInstanceOf ( Buffer )
@@ -204,7 +220,7 @@ describe('connection', () => {
204220 } )
205221
206222 it ( 'should test blob0' , done => {
207- connection . sendCommands ( 'TEST BLOB0' , ( error , results ) => {
223+ chinook . sendCommands ( 'TEST BLOB0' , ( error , results ) => {
208224 expect ( error ) . toBeNull ( )
209225 expect ( typeof results ) . toBe ( 'object' )
210226 expect ( results ) . toBeInstanceOf ( Buffer )
@@ -215,7 +231,7 @@ describe('connection', () => {
215231 } )
216232
217233 it ( 'should test error' , done => {
218- connection . sendCommands ( 'TEST ERROR' , ( error , results ) => {
234+ chinook . sendCommands ( 'TEST ERROR' , ( error , results ) => {
219235 expect ( error ) . toBeDefined ( )
220236 expect ( error ) . toBeInstanceOf ( SQLiteCloudError )
221237
@@ -230,7 +246,7 @@ describe('connection', () => {
230246 } )
231247
232248 it ( 'should test exterror' , done => {
233- connection . sendCommands ( 'TEST EXTERROR' , ( error , results ) => {
249+ chinook . sendCommands ( 'TEST EXTERROR' , ( error , results ) => {
234250 expect ( error ) . toBeDefined ( )
235251 expect ( error ) . toBeInstanceOf ( SQLiteCloudError )
236252
@@ -245,7 +261,7 @@ describe('connection', () => {
245261 } )
246262
247263 it ( 'should test array' , done => {
248- connection . sendCommands ( 'TEST ARRAY' , ( error , results ) => {
264+ chinook . sendCommands ( 'TEST ARRAY' , ( error , results ) => {
249265 expect ( error ) . toBeNull ( )
250266 expect ( Array . isArray ( results ) ) . toBe ( true )
251267
@@ -260,7 +276,7 @@ describe('connection', () => {
260276 } )
261277
262278 it ( 'should test rowset' , done => {
263- connection . sendCommands ( 'TEST ROWSET' , ( error , results ) => {
279+ chinook . sendCommands ( 'TEST ROWSET' , ( error , results ) => {
264280 expect ( results . numberOfRows ) . toBe ( 41 )
265281 expect ( results . numberOfColumns ) . toBe ( 2 )
266282 expect ( results . version == 1 || results . version == 2 ) . toBeTruthy ( )
@@ -272,7 +288,7 @@ describe('connection', () => {
272288 it (
273289 'should test chunked rowset' ,
274290 done => {
275- connection . sendCommands ( 'TEST ROWSET_CHUNK' , ( error , results ) => {
291+ chinook . sendCommands ( 'TEST ROWSET_CHUNK' , ( error , results ) => {
276292 expect ( results . numberOfRows ) . toBe ( 147 )
277293 expect ( results . numberOfColumns ) . toBe ( 1 )
278294 expect ( results . columnsNames ) . toEqual ( [ 'key' ] )
@@ -289,7 +305,7 @@ describe('connection', () => {
289305 let completed = 0
290306
291307 for ( let i = 0 ; i < numQueries ; i ++ ) {
292- connection . sendCommands ( `select ${ i } as "count", 'hello' as 'string'` , ( error , results ) => {
308+ chinook . sendCommands ( `select ${ i } as "count", 'hello' as 'string'` , ( error , results ) => {
293309 expect ( error ) . toBeNull ( )
294310 expect ( results . numberOfColumns ) . toBe ( 2 )
295311 expect ( results . numberOfRows ) . toBe ( 1 )
@@ -307,7 +323,7 @@ describe('connection', () => {
307323
308324 describe ( 'send select commands' , ( ) => {
309325 it ( 'should select long formatted string' , done => {
310- connection . sendCommands ( "USE DATABASE :memory:; select printf('%.*c', 1000, 'x') AS DDD" , ( error , results ) => {
326+ chinook . sendCommands ( "USE DATABASE :memory:; select printf('%.*c', 1000, 'x') AS DDD" , ( error , results ) => {
311327 expect ( results . numberOfColumns ) . toBe ( 1 )
312328 expect ( results . numberOfRows ) . toBe ( 1 )
313329 expect ( results . version == 1 || results . version == 2 ) . toBeTruthy ( )
@@ -321,7 +337,7 @@ describe('connection', () => {
321337 } )
322338
323339 it ( 'should select database' , done => {
324- connection . sendCommands ( 'USE DATABASE chinook.db;' , ( error , results ) => {
340+ chinook . sendCommands ( 'USE DATABASE chinook.db;' , ( error , results ) => {
325341 expect ( results . numberOfColumns ) . toBeUndefined ( )
326342 expect ( results . numberOfRows ) . toBeUndefined ( )
327343 expect ( results . version ) . toBeUndefined ( )
@@ -330,23 +346,23 @@ describe('connection', () => {
330346 } )
331347
332348 it ( 'should select * from tracks limit 10 (no chunks)' , done => {
333- connection . sendCommands ( 'SELECT * FROM tracks LIMIT 10;' , ( error , results ) => {
349+ chinook . sendCommands ( 'SELECT * FROM tracks LIMIT 10;' , ( error , results ) => {
334350 expect ( results . numberOfColumns ) . toBe ( 9 )
335351 expect ( results . numberOfRows ) . toBe ( 10 )
336352 done ( )
337353 } )
338354 } )
339355
340356 it ( 'should select * from tracks (with chunks)' , done => {
341- connection . sendCommands ( 'SELECT * FROM tracks;' , ( error , results ) => {
357+ chinook . sendCommands ( 'SELECT * FROM tracks;' , ( error , results ) => {
342358 expect ( results . numberOfColumns ) . toBe ( 9 )
343359 expect ( results . numberOfRows ) . toBe ( 3503 )
344360 done ( )
345361 } )
346362 } )
347363
348364 it ( 'should select * from albums' , done => {
349- connection . sendCommands ( 'SELECT * FROM albums;' , ( error , results ) => {
365+ chinook . sendCommands ( 'SELECT * FROM albums;' , ( error , results ) => {
350366 expect ( results . numberOfColumns ) . toBe ( 3 )
351367 expect ( results . numberOfRows ) . toBe ( 347 )
352368 expect ( results . version == 1 || results . version == 2 ) . toBeTruthy ( )
@@ -363,7 +379,7 @@ describe('connection', () => {
363379 let completed = 0
364380 const startTime = Date . now ( )
365381 for ( let i = 0 ; i < numQueries ; i ++ ) {
366- connection . sendCommands ( 'TEST STRING' , ( error , results ) => {
382+ chinook . sendCommands ( 'TEST STRING' , ( error , results ) => {
367383 expect ( results ) . toBe ( 'Hello World, this is a test string.' )
368384 if ( ++ completed >= numQueries ) {
369385 const queryMs = ( Date . now ( ) - startTime ) / numQueries
@@ -384,7 +400,7 @@ describe('connection', () => {
384400 let completed = 0
385401 const startTime = Date . now ( )
386402 for ( let i = 0 ; i < numQueries ; i ++ ) {
387- connection . sendCommands ( 'SELECT * FROM albums ORDER BY RANDOM() LIMIT 4;' , ( error , results ) => {
403+ chinook . sendCommands ( 'SELECT * FROM albums ORDER BY RANDOM() LIMIT 4;' , ( error , results ) => {
388404 expect ( error ) . toBeNull ( )
389405 expect ( results . numberOfColumns ) . toBe ( 3 )
390406 expect ( results . numberOfRows ) . toBe ( 4 )
@@ -407,7 +423,7 @@ describe('connection', () => {
407423 let completed = 0
408424 const startTime = Date . now ( )
409425 for ( let i = 0 ; i < numQueries ; i ++ ) {
410- connection . sendCommands (
426+ chinook . sendCommands (
411427 'SELECT * FROM albums ORDER BY RANDOM() LIMIT 16; SELECT * FROM albums ORDER BY RANDOM() LIMIT 12; SELECT * FROM albums ORDER BY RANDOM() LIMIT 8; SELECT * FROM albums ORDER BY RANDOM() LIMIT 4;' ,
412428 ( error , results ) => {
413429 // server only returns the last rowset?
0 commit comments