Skip to content

Commit 10f64b8

Browse files
authored
Allow tx timeout to be 0 and send it (#841)
Altering TestKit back end to treat exceptions on session.run and tx.run as `DriverError`s
1 parent c45a6b9 commit 10f64b8

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
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/neo4j-driver/test/bolt-v3.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import sharedNeo4j from './internal/shared-neo4j'
2323
const TX_CONFIG_WITH_METADATA = { metadata: { a: 1, b: 2 } }
2424
const TX_CONFIG_WITH_TIMEOUT = { timeout: 42 }
2525

26-
const INVALID_TIMEOUT_VALUES = [0, -1, -42, '15 seconds', [1, 2, 3]]
26+
const INVALID_TIMEOUT_VALUES = [-1, -42, '15 seconds', [1, 2, 3]]
2727
const INVALID_METADATA_VALUES = [
2828
'metadata',
2929
['1', '2', '3'],

packages/neo4j-driver/test/internal/tx-config.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ describe('#unit TxConfig', () => {
5252
})
5353

5454
it('should fail to construct with invalid timeout', () => {
55-
const invalidTimeoutValues = ['15s', [15], {}, 0, int(0), -42, int(-42)]
55+
const invalidTimeoutValues = ['15s', [15], {}, -42, int(-42)]
5656

5757
invalidTimeoutValues.forEach(invalidValue =>
5858
expect(() => new TxConfig({ timeout: invalidValue })).toThrow()
5959
)
6060
})
6161

6262
it('should construct with valid timeout', () => {
63+
testConfigCreationWithTimeout(0)
6364
testConfigCreationWithTimeout(1)
6465
testConfigCreationWithTimeout(42000)
6566

67+
testConfigCreationWithTimeout(int(0))
6668
testConfigCreationWithTimeout(int(1))
6769
testConfigCreationWithTimeout(int(424242))
6870
})

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)