Skip to content

TestKit tx lifetime #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 15 additions & 8 deletions packages/testkit-backend/src/controller/local.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Context from '../context'
import Controller from './interface'
import stringify from '../stringify'
import { isFrontendError } from '../request-handlers'


/**
Expand All @@ -24,7 +25,7 @@ export default class LocalController extends Controller {
closeContext (contextId) {
this._contexts.delete(contextId)
}

async handle (contextId, { name, data }) {
if (!this._contexts.has(contextId)) {
throw new Error(`Context ${contextId} does not exist`)
Expand Down Expand Up @@ -58,15 +59,21 @@ export default class LocalController extends Controller {

_writeError (contextId, e) {
if (e.name) {
const id = this._contexts.get(contextId).addError(e)
this._writeResponse(contextId, 'DriverError', {
id,
msg: e.message + ' (' + e.code + ')',
code: e.code
})
if (isFrontendError(e)) {
this._writeResponse(contextId, 'FrontendError', {
msg: 'Simulating the client code throwing some error.',
})
} else {
const id = this._contexts.get(contextId).addError(e)
this._writeResponse(contextId, 'DriverError', {
id,
msg: e.message + ' (' + e.code + ')',
code: e.code
})
}
return
}
this._writeBackendError(contextId, e)
}

}
21 changes: 13 additions & 8 deletions packages/testkit-backend/src/request-handlers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import neo4j from './neo4j'
import {
cypherToNative,
nativeToCypher,
import {
cypherToNative,
nativeToCypher,
} from './cypher-native-binders.js'
import {
nativeToTestkitSummary,
Expand All @@ -21,6 +21,14 @@ const SUPPORTED_TLS = (() => {
return [];
})();

export function throwFrontendError() {
throw new Error("TestKit FrontendError")
}

export function isFrontendError(error) {
return error.message === 'TestKit FrontendError'
}

export function NewDriver (context, data, wire) {
const {
uri,
Expand Down Expand Up @@ -107,8 +115,7 @@ export function DriverClose (context, data, wire) {
.then(() => {
wire.writeResponse('Driver', { id: driverId })
})
.catch(err => wire.writeError(err))
.finally(() => context.removeDriver(driverId))
.catch(err => wire.writeError(err))
}

export function NewSession (context, data, wire) {
Expand Down Expand Up @@ -213,8 +220,6 @@ export function ResultPeek (context, data, wire) {
}

export function ResultConsume (context, data, wire) {


const { resultId } = data
const result = context.getResult(resultId)

Expand Down Expand Up @@ -276,7 +281,7 @@ export function RetryablePositive (context, data, wire) {

export function RetryableNegative (context, data, wire) {
const { sessionId, errorId } = data
const error = context.getError(errorId) || new Error('Client error')
const error = context.getError(errorId) || new Error('TestKit FrontendError')
context.getTxsBySessionId(sessionId).forEach(tx => {
tx.reject(error)
})
Expand Down
4 changes: 4 additions & 0 deletions packages/testkit-backend/src/skipped-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ const skippedTests = [
skip(
'Results are always valid but don\'t return records when out of scope',
ifStartsWith('stub.iteration.test_result_scope.TestResultScope.')
),
skip(
'Driver (still) allows explicit managing of managed transaction',
ifEquals('stub.tx_lifetime.test_tx_lifetime.TestTxLifetime.test_managed_tx_raises_tx_managed_exec')
)
]

Expand Down