@@ -296,14 +296,13 @@ describe('SELECT', () => {
296
296
297
297
test ( 'compare with DateTime column' , async ( ) => {
298
298
const { dateTime : entity } = cds . entities ( 'basic.literals' )
299
- const dateTime = '1970-02-02T10:09:34Z'
300
- const timestamp = dateTime . slice ( 0 , - 1 ) + '.000Z'
301
- await DELETE . from ( entity )
302
- await INSERT ( { dateTime } ) . into ( entity )
303
- const dateTimeMatches = await SELECT ( 'dateTime' ) . from ( entity ) . where ( `dateTime = ` , dateTime )
304
- assert . strictEqual ( dateTimeMatches . length , 1 , 'Ensure that the dateTime column matches the dateTime value' )
305
- const timestampMatches = await SELECT ( 'dateTime' ) . from ( entity ) . where ( `dateTime = ` , timestamp )
306
- assert . strictEqual ( timestampMatches . length , 1 , 'Ensure that the dateTime column matches the timestamp value' )
299
+ const sel = SELECT ( 'dateTime' ) . from ( entity )
300
+ const [ { dateTime } ] = await sel . clone ( )
301
+ const timestamp = new Date ( dateTime )
302
+
303
+ expect ( await sel . clone ( ) . where ( `dateTime = ` , dateTime ) ) . length ( 1 )
304
+ expect ( await sel . clone ( ) . where ( `dateTime = ` , timestamp ) ) . length ( 1 )
305
+ expect ( await sel . clone ( ) . where ( `dateTime = ` , timestamp . toISOString ( ) ) ) . length ( 1 )
307
306
} )
308
307
309
308
test ( 'combine expr with nested functions and other compare' , async ( ) => {
@@ -526,7 +525,7 @@ describe('SELECT', () => {
526
525
let res
527
526
try {
528
527
res = await tx . run ( query )
529
- } catch ( err ) {
528
+ } catch ( err ) {
530
529
if ( tx . dbc . server . major < 4 ) return // not not is not supported by older HANA versions
531
530
throw err
532
531
}
@@ -617,7 +616,7 @@ describe('SELECT', () => {
617
616
618
617
test ( 'static val' , async ( ) => {
619
618
const { string } = cds . entities ( 'basic.literals' )
620
- const cqn = cds . ql `SELECT string FROM ${ string } GROUP BY string,${ 1 } `
619
+ const cqn = cds . ql `SELECT string FROM ${ string } GROUP BY string,${ '1' } `
621
620
const res = await cds . run ( cqn )
622
621
assert . strictEqual ( res . length , 3 , 'Ensure that all rows are coming back' )
623
622
} )
@@ -756,31 +755,39 @@ describe('SELECT', () => {
756
755
const isSQLite = ( ) => cds . db . options . impl === '@cap-js/sqlite'
757
756
758
757
const setMax = max => {
759
- let oldMax
758
+ let oldMax , oldTimeout
760
759
beforeAll ( async ( ) => {
761
- if ( isSQLite ( ) ) return
760
+ const options = cds . db . pools . _factory . options
761
+ oldMax = options . max
762
+ oldTimeout = options . acquireTimeoutMillis
763
+
764
+ if ( isSQLite ( ) ) {
765
+ oldTimeout = cds . db . pools . _factory . options . acquireTimeoutMillis
766
+ cds . db . pools . undefined . _config . acquireTimeoutMillis =
767
+ cds . db . pools . _factory . options . acquireTimeoutMillis = 1000
768
+ return
769
+ }
762
770
await cds . db . disconnect ( )
763
- oldMax = cds . db . pools . _factory . options . max
764
- cds . db . pools . _factory . options . max = max
771
+
772
+ options . max = max
773
+ options . acquireTimeoutMillis = 1000
765
774
} )
766
775
767
776
afterAll ( async ( ) => {
768
- if ( isSQLite ( ) ) return
769
- cds . db . pools . _factory . options . max = oldMax
770
- } )
771
- }
777
+ const options = cds . db . pools . _factory . options
772
778
773
- let oldTimeout
774
- beforeAll ( async ( ) => {
775
- oldTimeout = cds . db . pools . _factory . options . acquireTimeoutMillis
776
- cds . db . pools . undefined . _config . acquireTimeoutMillis =
777
- cds . db . pools . _factory . options . acquireTimeoutMillis = 1000
778
- } )
779
+ if ( isSQLite ( ) ) {
780
+ oldTimeout = cds . db . pools . _factory . options . acquireTimeoutMillis
781
+ cds . db . pools . undefined . _config . acquireTimeoutMillis =
782
+ cds . db . pools . _factory . options . acquireTimeoutMillis = 1000
783
+ return
784
+ }
785
+ await cds . db . disconnect ( )
779
786
780
- afterAll ( ( ) => {
781
- cds . db . pools . undefined . _config . acquireTimeoutMillis =
782
- cds . db . pools . _factory . options . acquireTimeoutMillis = oldTimeout
783
- } )
787
+ options . max = oldMax
788
+ options . acquireTimeoutMillis = oldTimeout
789
+ } )
790
+ }
784
791
785
792
describe ( 'pool max = 1' , ( ) => {
786
793
setMax ( 1 )
@@ -1524,20 +1531,26 @@ describe('SELECT', () => {
1524
1531
)
1525
1532
} )
1526
1533
1534
+ const os = require ( 'os' )
1527
1535
for ( let type of [ 'ref' , 'val' , 'func' , 'xpr' , 'list' , 'SELECT' ] ) {
1528
1536
describe ( `${ type } : ${ unified [ type ] . length } ` , ( ) => {
1529
1537
test ( 'execute' , async ( ) => {
1530
- // const batchCount = Math.min(os.availableParallelism() - 1, cds.db.factory.options.max || 1)
1531
- const batches = new Array ( 1 ) . fill ( '' )
1538
+ const batchCount = Math . min ( os . availableParallelism ( ) - 1 , cds . db . factory . options . max || 1 )
1539
+ const batches = new Array ( batchCount ) . fill ( '' )
1532
1540
const iterator = typeof unified [ type ] === 'function' ? unified [ type ] ( ) : unified [ type ] [ Symbol . iterator ] ( )
1533
1541
1534
1542
const { [ targetName ] : target } = cds . entities
1535
- await Promise . all ( batches . map ( ( ) => cds . tx ( async ( tx ) => {
1543
+ await Promise . all ( batches . map ( ( _ , i ) => cds . tx ( async ( tx ) => {
1536
1544
for ( const t of iterator ) {
1537
1545
// limit(0) still validates that the query is valid, but improves test execution time
1538
1546
await tx . run ( SELECT ( [ t ] ) . from ( target ) . limit ( 0 ) )
1539
1547
}
1540
- } ) ) )
1548
+ } )
1549
+ . catch ( err => {
1550
+ if ( err . name === 'TimeoutError' ) return
1551
+ throw err
1552
+ } ) )
1553
+ )
1541
1554
} )
1542
1555
} )
1543
1556
}
0 commit comments