Skip to content

teskit-backend: Enabling tests for Result.then #813

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 2 commits into from
Nov 11, 2021
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
19 changes: 17 additions & 2 deletions packages/testkit-backend/src/request-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export function SessionRun (context, data, wire) {
.then(_ => {
const result = session.run(cypher, params, { metadata, timeout })
const resultObserver = new ResultObserver({ sessionId, result })
result.subscribe(resultObserver)
const id = context.addResultObserver(resultObserver)
wire.writeResponse('Result', { id })
})
Expand Down Expand Up @@ -169,6 +168,22 @@ export function ResultConsume (context, data, wire) {
.catch(e => wire.writeError(e))
}

export function ResultList (context, data, wire) {
const { resultId } = data

const resultObserver = context.getResultObserver(resultId)
const result = resultObserver.result

result
.then(({ records }) => {
const cypherRecords = records.map(rec => {
return { values: Array.from(rec.values()).map(nativeToCypher) }
})
wire.writeResponse('RecordList', { records: cypherRecords})
})
.catch(error => wire.writeError(error))
}

export function SessionReadTransaction (context, data, wire) {
const { sessionId, txMeta: metadata } = data
const session = context.getSession(sessionId)
Expand All @@ -194,7 +209,6 @@ export function TransactionRun (context, data, wire) {
}
const result = tx.tx.run(cypher, params)
const resultObserver = new ResultObserver({ result })
result.subscribe(resultObserver)
const id = context.addResultObserver(resultObserver)
wire.writeResponse('Result', { id })
}
Expand Down Expand Up @@ -285,6 +299,7 @@ export function GetFeatures (_context, _params, wire) {
'Feature:Bolt:4.2',
'Feature:Bolt:4.3',
'Feature:Bolt:4.4',
'Feature:API:Result.List',
...SUPPORTED_TLS
]
})
Expand Down
14 changes: 14 additions & 0 deletions packages/testkit-backend/src/result-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class ResultObserver {
this.onCompleted = this.onCompleted.bind(this)
this.onError = this.onError.bind(this)
this._completitionPromise = null
this._subscribed = false
}

onKeys (keys) {
Expand All @@ -39,8 +40,13 @@ export default class ResultObserver {
this._completitionPromise = null
}

get result () {
return this._result
}

// Returns a promise, only one outstanding next!
next () {
this._subscribe()
return new Promise((resolve, reject) => {
this._promise = {
resolve,
Expand All @@ -51,6 +57,7 @@ export default class ResultObserver {
}

completitionPromise () {
this._subscribe()
return new Promise((resolve, reject) => {
if (this._summary) {
resolve(this._summary)
Expand Down Expand Up @@ -110,4 +117,11 @@ export default class ResultObserver {
promise.reject(err)
}
}

_subscribe () {
if (!this._subscribed) {
this._result.subscribe(this)
this._subscribed = true
}
}
}
12 changes: 12 additions & 0 deletions packages/testkit-backend/src/skipped-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ const skippedTests = [
ifEquals(
'neo4j.sessionrun.TestSessionRun.test_partial_iteration'
)
),
skip(
'Driver does not support mixing Result.subscribe with Result.then',
ifEquals(
'stub.iteration.test_result_list.TestResultList.test_tx_run_result_list_pulls_all_records_at_once_next_before_list'
),
ifEquals(
'stub.iteration.test_result_list.TestResultList.test_tx_func_result_list_pulls_all_records_at_once_next_before_list'
),
ifEquals(
'stub.iteration.test_result_list.TestResultList.test_session_run_result_list_pulls_all_records_at_once_next_before_list'
)
)
]

Expand Down