Skip to content

Commit 0845925

Browse files
author
Zhen
committed
Adding tests to ensure transient error caused by user canceling execution is not retried
1 parent 20d5280 commit 0845925

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
!: AUTO INIT
2+
!: AUTO RESET
3+
4+
C: RUN "BEGIN" {}
5+
PULL_ALL
6+
S: SUCCESS {"fields": []}
7+
SUCCESS {}
8+
9+
C: RUN "RETURN 1" {}
10+
PULL_ALL
11+
S: FAILURE {"code": "Neo.TransientError.Transaction.LockClientStopped", "message": "X"}
12+
IGNORED {}
13+
14+
C: ACK_FAILURE
15+
S: SUCCESS {}
16+
17+
C: RUN "ROLLBACK" {}
18+
PULL_ALL
19+
S: SUCCESS {}
20+
SUCCESS {}

test/stub/test_accesslevel.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# limitations under the License.
2020

2121

22-
from neo4j.v1 import GraphDatabase, CypherError
22+
from neo4j.v1 import GraphDatabase, CypherError, TransientError
2323

2424
from test.stub.tools import StubTestCase, StubCluster
2525

@@ -159,3 +159,25 @@ def unit_of_work_2(tx):
159159
assert value == 1
160160
value = session.read_transaction(unit_of_work_2)
161161
assert value == 2
162+
163+
def test_no_retry_read_on_user_canceled_tx(self):
164+
with StubCluster({9001: "router.script", 9004: "user_canceled_tx.script.script"}):
165+
uri = "bolt+routing://127.0.0.1:9001"
166+
with GraphDatabase.driver(uri, auth=self.auth_token, encrypted=False) as driver:
167+
with driver.session() as session:
168+
def unit_of_work(tx):
169+
tx.run("RETURN 1")
170+
171+
with self.assertRaises(TransientError):
172+
_ = session.read_transaction(unit_of_work)
173+
174+
def test_no_retry_write_on_user_canceled_tx(self):
175+
with StubCluster({9001: "router.script", 9006: "user_canceled_tx.script.script"}):
176+
uri = "bolt+routing://127.0.0.1:9001"
177+
with GraphDatabase.driver(uri, auth=self.auth_token, encrypted=False) as driver:
178+
with driver.session() as session:
179+
def unit_of_work(tx):
180+
tx.run("RETURN 1")
181+
182+
with self.assertRaises(TransientError):
183+
_ = session.write_transaction(unit_of_work)

0 commit comments

Comments
 (0)