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 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
27 changes: 14 additions & 13 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 @@ -25,7 +26,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 @@ -54,23 +55,23 @@ export default class LocalController extends Controller {

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

_msg (name, data) {
return {
name, data
}
}

}

function newResponse (name, data) {
Expand Down
19 changes: 12 additions & 7 deletions packages/testkit-backend/src/request-handlers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import neo4j from './neo4j'
import {
cypherToNative
} from './cypher-native-binders.js'
import { cypherToNative } from './cypher-native-binders.js'
import * as responses from './responses.js'

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 @@ -96,8 +102,7 @@ export function DriverClose (context, data, wire) {
.then(() => {
wire.writeResponse(responses.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 @@ -254,7 +259,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 All @@ -263,7 +268,7 @@ export function RetryableNegative (context, data, wire) {
export function SessionBeginTransaction (context, data, wire) {
const { sessionId, txMeta: metadata, timeout } = data
const session = context.getSession(sessionId)

try {
return session.beginTransaction({ metadata, timeout })
.then(tx => {
Expand Down
12 changes: 12 additions & 0 deletions packages/testkit-backend/src/skipped-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ 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')
),
skip(
'Flaky tests, requires investigation',
ifEndsWith('.test_should_fail_when_reading_from_unexpectedly_interrupting_readers_using_tx_function')
),
skip(
'Flaky tests, requires investigation',
ifEndsWith('.test_should_fail_when_writing_to_unexpectedly_interrupting_writers_using_tx_function')
)
]

Expand Down