@@ -203,33 +203,49 @@ def run(tx):
203
203
self .assertEqual (res , list (map (types .CypherInt , range (1 , 5 ))))
204
204
205
205
def test_tx_timeout (self ):
206
+ class WrappedError (Exception ):
207
+ def __init__ (self , inner ):
208
+ super ().__init__ ()
209
+ self .inner = inner
210
+
206
211
# TODO: remove this block once all languages work
207
212
if get_driver_name () in ["javascript" , "java" ]:
208
213
self .skipTest ("Query update2 does not time out." )
209
214
if get_driver_name () in ["dotnet" ]:
210
215
self .skipTest ("Backend crashes." )
211
216
217
+ lock_error_code = "Neo.ClientError.Transaction.LockClientStopped"
218
+
212
219
def create (tx ):
213
220
summary = tx .run ("MERGE (:Node)" ).consume ()
214
221
return summary .database
215
222
216
223
def update1 (tx ):
217
224
tx .run ("MATCH (a:Node) SET a.property = 1" ).consume ()
218
225
219
- with self .assertRaises (types . FrontendError ) :
226
+ with self .assertRaises (Exception ) as e :
220
227
self ._session2 .execute_write (update2 , timeout = 250 )
228
+ inner = e .exception
229
+ if isinstance (inner , WrappedError ):
230
+ inner = inner .inner
231
+ if (
232
+ not isinstance (inner , types .DriverError )
233
+ or inner .code != lock_error_code
234
+ ):
235
+ # This is not the error we are looking for. Maybe there was a
236
+ # leader election or so. Give the driver the chance to retry.
237
+ raise inner
221
238
222
- def update2 (tx ):
223
239
nonlocal exc
224
- with self .assertRaises (types .DriverError ) as e :
240
+ exc = inner
241
+
242
+ def update2 (tx ):
243
+ inner = None
244
+ try :
225
245
tx .run ("MATCH (a:Node) SET a.property = 2" ).consume ()
226
- exc = e .exception
227
- if exc .code == "Neo.ClientError.Transaction.LockClientStopped" :
228
- # This is the error we are looking for. Maybe there was a
229
- # leader election or so. Give the driver the chance to retry.
230
- raise ApplicationCodeError ("Stop, hammer time!" )
231
- else :
232
- raise exc
246
+ except types .DriverError as e :
247
+ inner = e
248
+ raise WrappedError (inner )
233
249
234
250
exc = None
235
251
@@ -240,9 +256,7 @@ def update2(tx):
240
256
)
241
257
self ._session1 .execute_write (update1 )
242
258
self .assertIsInstance (exc , types .DriverError )
243
-
244
- self .assertEqual (exc .code ,
245
- "Neo.ClientError.Transaction.LockClientStopped" )
259
+ self .assertEqual (exc .code , lock_error_code )
246
260
if get_driver_name () in ["python" ]:
247
- self . assertEqual ( exc . errorType ,
248
- "<class 'neo4j.exceptions.ClientError'>" )
261
+ error_type = "<class 'neo4j.exceptions.ClientError'>"
262
+ self . assertEqual ( exc . errorType , error_type )
0 commit comments