Skip to content

Commit e38d125

Browse files
authored
TestKit tx lifetime (#872)
* Properly handle TestKit's FrontendError * Add TestKit test skip for unified tx lifetime
1 parent 17727e9 commit e38d125

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

packages/testkit-backend/src/controller/local.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Context from '../context'
22
import Controller from './interface'
33
import stringify from '../stringify'
4+
import { isFrontendError } from '../request-handlers'
45

56

67
/**
@@ -25,7 +26,7 @@ export default class LocalController extends Controller {
2526
closeContext (contextId) {
2627
this._contexts.delete(contextId)
2728
}
28-
29+
2930
async handle (contextId, { name, data }) {
3031
if (!this._contexts.has(contextId)) {
3132
throw new Error(`Context ${contextId} does not exist`)
@@ -54,23 +55,23 @@ export default class LocalController extends Controller {
5455

5556
_writeError (contextId, e) {
5657
if (e.name) {
57-
const id = this._contexts.get(contextId).addError(e)
58-
this._writeResponse(contextId, newResponse('DriverError', {
59-
id,
60-
msg: e.message + ' (' + e.code + ')',
61-
code: e.code
62-
}))
58+
if (isFrontendError(e)) {
59+
this._writeResponse(contextId, newResponse('FrontendError', {
60+
msg: 'Simulating the client code throwing some error.',
61+
}))
62+
} else {
63+
const id = this._contexts.get(contextId).addError(e)
64+
this._writeResponse(contextId, newResponse('DriverError', {
65+
id,
66+
msg: e.message + ' (' + e.code + ')',
67+
code: e.code
68+
}))
69+
}
6370
return
6471
}
6572
this._writeBackendError(contextId, e)
6673
}
6774

68-
_msg (name, data) {
69-
return {
70-
name, data
71-
}
72-
}
73-
7475
}
7576

7677
function newResponse (name, data) {

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import neo4j from './neo4j'
2-
import {
3-
cypherToNative
4-
} from './cypher-native-binders.js'
2+
import { cypherToNative } from './cypher-native-binders.js'
53
import * as responses from './responses.js'
64

5+
export function throwFrontendError() {
6+
throw new Error("TestKit FrontendError")
7+
}
8+
9+
export function isFrontendError(error) {
10+
return error.message === 'TestKit FrontendError'
11+
}
12+
713
export function NewDriver (context, data, wire) {
814
const {
915
uri,
@@ -96,8 +102,7 @@ export function DriverClose (context, data, wire) {
96102
.then(() => {
97103
wire.writeResponse(responses.Driver({ id: driverId }))
98104
})
99-
.catch(err => wire.writeError(err))
100-
.finally(() => context.removeDriver(driverId))
105+
.catch(err => wire.writeError(err))
101106
}
102107

103108
export function NewSession (context, data, wire) {
@@ -254,7 +259,7 @@ export function RetryablePositive (context, data, wire) {
254259

255260
export function RetryableNegative (context, data, wire) {
256261
const { sessionId, errorId } = data
257-
const error = context.getError(errorId) || new Error('Client error')
262+
const error = context.getError(errorId) || new Error('TestKit FrontendError')
258263
context.getTxsBySessionId(sessionId).forEach(tx => {
259264
tx.reject(error)
260265
})
@@ -263,7 +268,7 @@ export function RetryableNegative (context, data, wire) {
263268
export function SessionBeginTransaction (context, data, wire) {
264269
const { sessionId, txMeta: metadata, timeout } = data
265270
const session = context.getSession(sessionId)
266-
271+
267272
try {
268273
return session.beginTransaction({ metadata, timeout })
269274
.then(tx => {

packages/testkit-backend/src/skipped-tests/common.js

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ const skippedTests = [
137137
skip(
138138
'Results are always valid but don\'t return records when out of scope',
139139
ifStartsWith('stub.iteration.test_result_scope.TestResultScope.')
140+
),
141+
skip(
142+
'Driver (still) allows explicit managing of managed transaction',
143+
ifEquals('stub.tx_lifetime.test_tx_lifetime.TestTxLifetime.test_managed_tx_raises_tx_managed_exec')
144+
),
145+
skip(
146+
'Flaky tests, requires investigation',
147+
ifEndsWith('.test_should_fail_when_reading_from_unexpectedly_interrupting_readers_using_tx_function')
148+
),
149+
skip(
150+
'Flaky tests, requires investigation',
151+
ifEndsWith('.test_should_fail_when_writing_to_unexpectedly_interrupting_writers_using_tx_function')
140152
)
141153
]
142154

0 commit comments

Comments
 (0)