Skip to content

Commit 94a7e9d

Browse files
authored
Raise error on run asap (#253)
* New tests: driver should raise error on run immediately * Activate Go's and JS's 4.4 branches in run_all.py
1 parent 843bd02 commit 94a7e9d

File tree

9 files changed

+97
-9
lines changed

9 files changed

+97
-9
lines changed

run_all.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
"branch-translation": {
2121
"4.0": "4.2",
2222
"4.1": "4.2",
23-
# TODO: until a 4.4 branch has been created
24-
"4.4": "4.3",
2523
}
2624
},
2725
{
@@ -36,8 +34,6 @@
3634
" XX XXX ",
3735
],
3836
"branch-translation": {
39-
# TODO: until a 4.4 branch has been created
40-
"4.4": "4.3",
4137
}
4238
},
4339
{

tests/stub/authorization/test_authorization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ def test_should_fail_with_auth_expired_on_run_using_tx_run(self):
181181
try:
182182
result = tx.run("RETURN 1 as n")
183183
# TODO remove consume() once all drivers report the error on run
184-
result.consume()
184+
if get_driver_name() in ["javascript", "dotnet"]:
185+
result.consume()
185186
except types.DriverError as e:
186187
self.assert_is_authorization_error(error=e)
187188
session.close()

tests/stub/session_run/scripts/session_consume_result.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A: HELLO {"{}": "*"}
44
*: RESET
5-
C: RUN {"U": "*"}{"{}": "*"} {"{}": "*"}
5+
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
66
S: SUCCESS {"fields": ["n"]}
77
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
88
S: RECORD [1]

tests/stub/session_run/scripts/session_discard_result.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A: HELLO {"{}": "*"}
44
*: RESET
5-
C: RUN {"U": "*"}{"{}": "*"} {"{}": "*"}
5+
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
66
S: SUCCESS {"fields": ["n"]}
77
{*
88
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
!: BOLT 4.4
2+
3+
A: HELLO {"{}": "*"}
4+
*: RESET
5+
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
6+
S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."}
7+
{?
8+
# For drivers that pipeline a PULL after RUN
9+
C: PULL {"n": {"Z": "*"}}
10+
S: IGNORED
11+
?}
12+
+: RESET
13+
?: GOODBYE

tests/stub/session_run/test_session_run.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setUp(self):
1919
def tearDown(self):
2020
if self._session is not None:
2121
self._session.close()
22-
self._server.done()
22+
self._server.reset()
2323
super().tearDown()
2424

2525
def test_discard_on_session_close_untouched_result(self):
@@ -77,3 +77,16 @@ def test_no_discard_on_session_close_finished_result(self):
7777
self._session.close()
7878
self._session = None
7979
self._server.done()
80+
81+
def test_raises_error_on_session_run(self):
82+
# TODO: remove this block once all languages work
83+
if get_driver_name() in ["javascript", "dotnet"]:
84+
self.skipTest("Driver reports error too late.")
85+
self._server.start(
86+
path=self.script_path("session_error_on_run.script")
87+
)
88+
self._session = self._driver.session("r")
89+
with self.assertRaises(types.DriverError) as exc:
90+
self._session.run("RETURN 1 AS n")
91+
self.assertEqual(exc.exception.code, "Neo.ClientError.MadeUp.Code")
92+
self._server.done()

tests/stub/tx_run/scripts/tx_discard_then_rollback.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A: HELLO {"{}": "*"}
44
*: RESET
55
C: BEGIN {"{}": "*"}
66
S: SUCCESS {}
7-
C: RUN {"U": "*"}{"{}": "*"} {"{}": "*"}
7+
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
88
S: SUCCESS {"fields": ["n"]}
99
{*
1010
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
!: BOLT 4.4
2+
3+
A: HELLO {"{}": "*"}
4+
*: RESET
5+
C: BEGIN {"{}": "*"}
6+
S: SUCCESS {}
7+
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
8+
S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."}
9+
{?
10+
# For drivers that pipeline a PULL after RUN
11+
C: PULL {"n": {"Z": "*"}, "[qid]": -1}
12+
S: IGNORED
13+
?}
14+
+: RESET
15+
?: GOODBYE

tests/stub/tx_run/test_tx_run.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,53 @@ def test_eager_begin_on_tx_run_with_disconnect_on_begin(self):
194194
def test_eager_begin_on_tx_run_with_error_on_begin(self):
195195
exc = self._eager_tx_run("tx_error_on_begin.script")
196196
self.assertEqual("Neo.ClientError.MadeUp.Code", exc.code)
197+
198+
def test_raises_error_on_tx_run(self):
199+
# TODO: remove this block once all languages work
200+
if get_driver_name() in ["javascript", "dotnet"]:
201+
self.skipTest("Driver reports error too late.")
202+
self._server1.start(
203+
path=self.script_path("tx_error_on_run.script")
204+
)
205+
self._create_direct_driver()
206+
self._session = self._driver.session("r")
207+
tx = self._session.beginTransaction()
208+
with self.assertRaises(types.DriverError) as exc:
209+
tx.run("RETURN 1 AS n")
210+
self.assertEqual(exc.exception.code, "Neo.ClientError.MadeUp.Code")
211+
# TODO: remove whole try/catch once all drivers allow to rollback a
212+
# failed transaction silently.
213+
try:
214+
tx.rollback()
215+
except types.DriverError as exc:
216+
if get_driver_name() in ["go"]:
217+
self.assertEqual(exc.code, "Neo.ClientError.MadeUp.Code")
218+
else:
219+
raise
220+
221+
def test_raises_error_on_tx_func_run(self):
222+
# TODO: remove this block once all languages work
223+
if get_driver_name() in ["javascript", "dotnet"]:
224+
self.skipTest("Driver reports error too late.")
225+
work_call_count = 0
226+
227+
def work(tx):
228+
nonlocal work_call_count
229+
self.assertEqual(work_call_count, 0)
230+
work_call_count += 1
231+
232+
with self.assertRaises(types.DriverError) as exc_:
233+
tx.run("RETURN 1 AS n")
234+
self.assertEqual(exc_.exception.code, "Neo.ClientError.MadeUp.Code")
235+
raise exc_.exception
236+
237+
if get_driver_name() in ["javascript_", "dotnet_"]:
238+
self.skipTest("Driver reports error too late.")
239+
self._server1.start(
240+
path=self.script_path("tx_error_on_run.script")
241+
)
242+
self._create_direct_driver()
243+
self._session = self._driver.session("r")
244+
with self.assertRaises(types.DriverError) as exc:
245+
self._session.readTransaction(work)
246+
self.assertEqual(exc.exception.code, "Neo.ClientError.MadeUp.Code")

0 commit comments

Comments
 (0)