Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class HANAService extends SQLService {
// Clear current tenant connection pool
this.disconnect(this.context.tenant)
}
throw err
return this.rollback(err)
}
}

Expand Down
51 changes: 51 additions & 0 deletions hana/test/lock.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { tx } = require('@sap/cds')

Check warning on line 1 in hana/test/lock.test.js

View workflow job for this annotation

GitHub Actions / Tests (22)

'tx' is assigned a value but never used
const cds = require('../../test/cds.js')

describe('locking', () => {
const { expect } = cds.test(__dirname + '/../../test/bookshop')

describe('forUpdate', async () => {

test('wait=0', async () => {
const { Books } = cds.entities
let tx1, tx2
try {
tx1 = await cds.tx()
tx2 = await cds.tx()
const query = cds.ql.SELECT.from(Books).forUpdate({ wait: 0 })

await tx1.run(query)
await expect(tx2.run(query)).rejected
} finally {
await tx1?.rollback()
await tx2?.rollback()
}
})

test('wait>0', async () => {
const { Books } = cds.entities
let tx1, tx2
try {
tx1 = await cds.tx()
tx2 = await cds.tx()
const query = cds.ql.SELECT.from(Books).forUpdate({ wait: 1 })

await tx2.run(INSERT({ ID: 999 }).into(Books))

await tx1.run(query)

await expect(tx2.run(query)).rejected

await tx2.commit()
await tx1.commit()

const res = await cds.ql.SELECT.from(Books).where({ ID: 999 })
expect(res).length(0)
} finally {
await tx1?.rollback()
await tx2?.rollback()
}
})

})
})
Loading