Skip to content
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

Raise error on run asap #253

Merged
merged 4 commits into from
Sep 22, 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
4 changes: 0 additions & 4 deletions run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
"branch-translation": {
"4.0": "4.2",
"4.1": "4.2",
# TODO: until a 4.4 branch has been created
"4.4": "4.3",
}
},
{
Expand All @@ -36,8 +34,6 @@
" XX XXX ",
],
"branch-translation": {
# TODO: until a 4.4 branch has been created
"4.4": "4.3",
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/authorization/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_should_fail_with_auth_expired_on_run_using_tx_run(self):
try:
result = tx.run("RETURN 1 as n")
# TODO remove consume() once all drivers report the error on run
result.consume()
if get_driver_name() in ["javascript", "dotnet"]:
result.consume()
except types.DriverError as e:
self.assert_is_authorization_error(error=e)
session.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A: HELLO {"{}": "*"}
*: RESET
C: RUN {"U": "*"}{"{}": "*"} {"{}": "*"}
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
S: SUCCESS {"fields": ["n"]}
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
S: RECORD [1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A: HELLO {"{}": "*"}
*: RESET
C: RUN {"U": "*"}{"{}": "*"} {"{}": "*"}
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
S: SUCCESS {"fields": ["n"]}
{*
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
Expand Down
13 changes: 13 additions & 0 deletions tests/stub/session_run/scripts/session_error_on_run.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!: BOLT 4.4

A: HELLO {"{}": "*"}
*: RESET
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."}
{?
# For drivers that pipeline a PULL after RUN
C: PULL {"n": {"Z": "*"}}
S: IGNORED
?}
+: RESET
?: GOODBYE
15 changes: 14 additions & 1 deletion tests/stub/session_run/test_session_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
def tearDown(self):
if self._session is not None:
self._session.close()
self._server.done()
self._server.reset()
super().tearDown()

def test_discard_on_session_close_untouched_result(self):
Expand Down Expand Up @@ -77,3 +77,16 @@ def test_no_discard_on_session_close_finished_result(self):
self._session.close()
self._session = None
self._server.done()

def test_raises_error_on_session_run(self):
# TODO: remove this block once all languages work
if get_driver_name() in ["javascript", "dotnet"]:
self.skipTest("Driver reports error too late.")
self._server.start(
path=self.script_path("session_error_on_run.script")
)
self._session = self._driver.session("r")
with self.assertRaises(types.DriverError) as exc:
self._session.run("RETURN 1 AS n")
self.assertEqual(exc.exception.code, "Neo.ClientError.MadeUp.Code")
self._server.done()
2 changes: 1 addition & 1 deletion tests/stub/tx_run/scripts/tx_discard_then_rollback.script
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A: HELLO {"{}": "*"}
*: RESET
C: BEGIN {"{}": "*"}
S: SUCCESS {}
C: RUN {"U": "*"}{"{}": "*"} {"{}": "*"}
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
S: SUCCESS {"fields": ["n"]}
{*
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
Expand Down
15 changes: 15 additions & 0 deletions tests/stub/tx_run/scripts/tx_error_on_run.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!: BOLT 4.4

A: HELLO {"{}": "*"}
*: RESET
C: BEGIN {"{}": "*"}
S: SUCCESS {}
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."}
{?
# For drivers that pipeline a PULL after RUN
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
S: IGNORED
?}
+: RESET
?: GOODBYE
50 changes: 50 additions & 0 deletions tests/stub/tx_run/test_tx_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,53 @@ def test_eager_begin_on_tx_run_with_disconnect_on_begin(self):
def test_eager_begin_on_tx_run_with_error_on_begin(self):
exc = self._eager_tx_run("tx_error_on_begin.script")
self.assertEqual("Neo.ClientError.MadeUp.Code", exc.code)

def test_raises_error_on_tx_run(self):
# TODO: remove this block once all languages work
if get_driver_name() in ["javascript", "dotnet"]:
self.skipTest("Driver reports error too late.")
self._server1.start(
path=self.script_path("tx_error_on_run.script")
)
self._create_direct_driver()
self._session = self._driver.session("r")
tx = self._session.beginTransaction()
with self.assertRaises(types.DriverError) as exc:
tx.run("RETURN 1 AS n")
self.assertEqual(exc.exception.code, "Neo.ClientError.MadeUp.Code")
# TODO: remove whole try/catch once all drivers allow to rollback a
# failed transaction silently.
try:
tx.rollback()
except types.DriverError as exc:
if get_driver_name() in ["go"]:
self.assertEqual(exc.code, "Neo.ClientError.MadeUp.Code")
else:
raise

def test_raises_error_on_tx_func_run(self):
# TODO: remove this block once all languages work
if get_driver_name() in ["javascript", "dotnet"]:
self.skipTest("Driver reports error too late.")
work_call_count = 0

def work(tx):
nonlocal work_call_count
self.assertEqual(work_call_count, 0)
work_call_count += 1

with self.assertRaises(types.DriverError) as exc_:
tx.run("RETURN 1 AS n")
self.assertEqual(exc_.exception.code, "Neo.ClientError.MadeUp.Code")
raise exc_.exception

if get_driver_name() in ["javascript_", "dotnet_"]:
self.skipTest("Driver reports error too late.")
self._server1.start(
path=self.script_path("tx_error_on_run.script")
)
self._create_direct_driver()
self._session = self._driver.session("r")
with self.assertRaises(types.DriverError) as exc:
self._session.readTransaction(work)
self.assertEqual(exc.exception.code, "Neo.ClientError.MadeUp.Code")