Skip to content

Commit

Permalink
Add tx termination test based on failed tx.run
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives committed Jun 28, 2023
1 parent a65e34f commit b00eda3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/stub/tx_run/scripts/tx_successful_and_failing_streams.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
!: BOLT 4.4

A: HELLO {"{}": "*"}
*: RESET
C: BEGIN {"{}": "*"}
S: SUCCESS {}
C: RUN "RETURN 1 AS n" {"{}": "*"} {"{}": "*"}
PULL {"n": {"Z": "*"}, "[qid]": -1}
S: SUCCESS {"fields": ["n"], "qid": 1}
RECORD [1]
RECORD [2]
SUCCESS {"has_more": true, "type": "r"}
C: RUN "invalid" {"{}": "*"} {"{}": "*"}
PULL {"n": {"Z": "*"}, "[qid]": -1}
S: FAILURE {"code": "Neo.ClientError.Statement.SyntaxError", "message": "Invalid input"}
IGNORED
*: RESET
?: GOODBYE
24 changes: 24 additions & 0 deletions tests/stub/tx_run/test_tx_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,27 @@ def test_failed_tx_run_allows_rollback(self):

def test_failed_tx_run_allows_skipping_rollback(self):
self._test_failed_tx_run(rollback=False)

@driver_feature(types.Feature.OPT_PULL_PIPELINING)
def test_should_terminate_tx_after_failed_run(self):
self._create_direct_driver()
self._server1.start(
path=self.script_path("tx_successful_and_failing_streams.script")
)
self._session = self._driver.session("r", fetch_size=2)
tx = self._session.begin_transaction()
res = tx.run("RETURN 1 AS n")
with self.assertRaises(types.DriverError) as exc:
tx.run("invalid")
self.assertEqual(exc.exception.code, "Neo.ClientError.Statement.SyntaxError")

# while already buffered records may be accessible, there must be no
# further PULLs and an exception must be raised
with self.assertRaises(types.DriverError):
for i in range(0, 3):
res.next()

tx.close()
self._session.close()
self._session = None
self._server1.done()

0 comments on commit b00eda3

Please sign in to comment.