Skip to content

Commit afd129a

Browse files
committed
Allow tx timeout to be 0 and send it
Altering TestKit back end to treat exceptions on session.run and tx.run as `DriverError`s
1 parent 34b4750 commit afd129a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

packages/bolt-connection/src/bolt/request-message.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export default class RequestMessage {
256256
if ( databaseContext.databaseName ) {
257257
dbContext.db = databaseContext.databaseName
258258
}
259-
259+
260260
if ( databaseContext.impersonatedUser ) {
261261
dbContext.imp_user = databaseContext.impersonatedUser
262262
}
@@ -286,7 +286,7 @@ function buildTxMetadata (bookmark, txConfig, database, mode, impersonatedUser)
286286
if (!bookmark.isEmpty()) {
287287
metadata.bookmarks = bookmark.values()
288288
}
289-
if (txConfig.timeout) {
289+
if (txConfig.timeout != null) {
290290
metadata.tx_timeout = txConfig.timeout
291291
}
292292
if (txConfig.metadata) {

packages/core/src/internal/tx-config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ function extractTimeout(config: any): Integer | null {
6767
if (util.isObject(config) && (config.timeout || config.timeout === 0)) {
6868
util.assertNumberOrInteger(config.timeout, 'Transaction timeout')
6969
const timeout = int(config.timeout)
70-
if (timeout.isZero()) {
71-
throw newError('Transaction timeout should not be zero')
72-
}
7370
if (timeout.isNegative()) {
7471
throw newError('Transaction timeout should not be negative')
7572
}

packages/testkit-backend/src/request-handlers.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ export function SessionRun (context, data, wire) {
153153
Promise.all(observers.map(obs => obs.completitionPromise()))
154154
.catch(_ => null)
155155
.then(_ => {
156-
const result = session.run(cypher, params, { metadata, timeout })
156+
let result
157+
try {
158+
result = session.run(cypher, params, { metadata, timeout })
159+
} catch (e) {
160+
console.log('got some err: ' + JSON.stringify(e))
161+
wire.writeError(e)
162+
return
163+
}
157164
const resultObserver = new ResultObserver({ sessionId, result })
158165
const id = context.addResultObserver(resultObserver)
159166
wire.writeResponse('Result', { id })
@@ -261,7 +268,14 @@ export function RetryableNegative (context, data, wire) {
261268
export function SessionBeginTransaction (context, data, wire) {
262269
const { sessionId, txMeta: metadata, timeout } = data
263270
const session = context.getSession(sessionId)
264-
const tx = session.beginTransaction({ metadata, timeout })
271+
let tx
272+
try {
273+
tx = session.beginTransaction({ metadata, timeout })
274+
} catch (e) {
275+
console.log('got some err: ' + JSON.stringify(e))
276+
wire.writeError(e)
277+
return
278+
}
265279
const id = context.addTx(tx, sessionId)
266280
wire.writeResponse('Transaction', { id })
267281
}

0 commit comments

Comments
 (0)