Skip to content

Commit 0d1bfda

Browse files
authored
Add tests for omitting qid when possible (#249)
1 parent 008d872 commit 0d1bfda

File tree

6 files changed

+202
-13
lines changed

6 files changed

+202
-13
lines changed

tests/stub/iteration/scripts/v4x0/tx_pull_1_nested.script

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ A: HELLO {"{}": "*"}
55
C: BEGIN {}
66
S: SUCCESS {}
77
C: RUN "CYPHER" {} {}
8-
PULL {"n": 1}
98
S: SUCCESS {"fields": ["x"], "qid": 1}
10-
RECORD ["1_1"]
9+
C: PULL {"n": 1, "[qid]": 1}
10+
S: RECORD ["1_1"]
1111
SUCCESS {"has_more": true}
1212
C: RUN "CYPHER" {} {}
13-
PULL {"n": 1}
1413
S: SUCCESS {"fields": ["x"], "qid": 2}
15-
RECORD ["2_1"]
14+
C: PULL {"n": 1, "[qid]": 2}
15+
S: RECORD ["2_1"]
1616
SUCCESS {"has_more": true}
17-
C: PULL {"n": 1, "qid": 2}
17+
C: PULL {"n": 1, "[qid]": 2}
1818
S: RECORD ["2_2"]
1919
SUCCESS {}
2020
C: PULL {"n": 1, "qid": 1}
2121
S: RECORD ["1_2"]
2222
SUCCESS {}
2323
C: RUN "CYPHER" {} {}
24-
PULL {"n": 1}
2524
S: SUCCESS {"fields": ["x"], "qid": 3}
26-
RECORD ["3_1"]
25+
C: PULL {"n": 1, "[qid]": 3}
26+
S: RECORD ["3_1"]
2727
SUCCESS {}
2828
C: COMMIT
2929
S: SUCCESS {"bookmark": "bm"}

tests/stub/iteration/scripts/v4x0/tx_pull_2.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ C: PULL {"n": 2, "[qid]": 7}
1010
S: RECORD [1]
1111
RECORD [2]
1212
SUCCESS {"has_more": true}
13-
C: PULL {"n": 2, "qid": 7}
13+
C: PULL {"n": 2, "[qid]": 7}
1414
S: RECORD [3]
1515
SUCCESS {}
1616
C: COMMIT

tests/stub/optimizations/scripts/v4x3/all_default.script

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"}
88
C: BEGIN {}
99
S: SUCCESS {}
1010
C: RUN "*" {} {}
11-
S: SUCCESS {"fields": ["1"]}
11+
S: SUCCESS {"fields": ["1"], "qid": 1}
1212
{{
1313
C: PULL {"n": "*"}
1414
S: RECORD [1]
15+
SUCCESS {"has_more": true}
16+
{{
17+
C: PULL {"n": "*"}
18+
S: RECORD [1]
19+
----
20+
# Drivers that pipeline a PULL will takes this path in the discarding tests
21+
C: DISCARD {"n": "*"}
22+
}}
1523
----
16-
C: DISCARD {}
24+
# Drivers that don't pipeline a PULL will takes this path in the discarding tests
25+
C: DISCARD {"n": "*"}
1726
}}
1827
S: SUCCESS {}
1928
C: COMMIT
@@ -25,11 +34,19 @@ S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"}
2534
{{
2635
C: PULL {"n": "*"}
2736
S: RECORD [1]
37+
SUCCESS {"has_more": true}
38+
{{
39+
C: PULL {"n": "*"}
40+
S: RECORD [1]
41+
----
42+
# Drivers that pipeline a PULL will takes this path in the discarding tests
43+
C: DISCARD {"n": "*"}
44+
}}
2845
----
29-
C: DISCARD {}
46+
# Drivers that don't pipeline a PULL will takes this path in the discarding tests
47+
C: DISCARD {"n": "*"}
3048
}}
31-
S: RECORD [1]
32-
SUCCESS {"type": "w", "bookmark": "bookmark:1"}
49+
S: SUCCESS {"type": "w", "bookmark": "bookmark:1"}
3350
}}
3451
*: RESET
3552
?: GOODBYE
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
!: BOLT 4.3
2+
3+
C: HELLO {"user_agent": "*", "scheme": "basic", "principal": "*", "credentials": "*"}
4+
S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"}
5+
*: RESET
6+
C: BEGIN {}
7+
S: SUCCESS {}
8+
C: RUN "*" {} {}
9+
S: SUCCESS {"fields": ["1"], "qid": 1}
10+
{{
11+
C: PULL {"n": "*"}
12+
S: RECORD [1]
13+
SUCCESS {"has_more": true}
14+
{{
15+
C: PULL {"n": "*"}
16+
S: RECORD [1]
17+
----
18+
# Drivers that pipeline a PULL will takes this path in the discarding tests
19+
C: DISCARD {"n": "*"}
20+
}}
21+
----
22+
# Drivers that don't pipeline a PULL will takes this path in the discarding tests
23+
C: DISCARD {"n": "*"}
24+
}}
25+
S: SUCCESS {}
26+
C: RUN "*" {} {}
27+
S: SUCCESS {"fields": ["2"], "qid": 2}
28+
{{
29+
C: PULL {"n": "*"}
30+
S: RECORD [1]
31+
SUCCESS {"has_more": true}
32+
{{
33+
C: PULL {"n": "*"}
34+
S: RECORD [1]
35+
----
36+
# Drivers that pipeline a PULL will takes this path in the discarding tests
37+
C: DISCARD {"n": "*"}
38+
}}
39+
----
40+
# Drivers that don't pipeline a PULL will takes this path in the discarding tests
41+
C: DISCARD {"n": "*"}
42+
}}
43+
S: SUCCESS {}
44+
C: COMMIT
45+
S: SUCCESS {"type": "w", "bookmark": "bookmark:1"}
46+
*: RESET
47+
?: GOODBYE
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
!: BOLT 4.3
2+
3+
C: HELLO {"user_agent": "*", "scheme": "basic", "principal": "*", "credentials": "*"}
4+
S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"}
5+
*: RESET
6+
C: BEGIN {}
7+
S: SUCCESS {}
8+
C: RUN "*" {} {}
9+
S: SUCCESS {"fields": ["1"], "qid": 1}
10+
C: PULL {"n": "*"}
11+
S: RECORD [1]
12+
SUCCESS {"has_more": true}
13+
{?
14+
# Eager drivers might pull a record in advance
15+
C: PULL {"n": "*"}
16+
S: RECORD [1]
17+
SUCCESS {"has_more": true}
18+
?}
19+
C: RUN "*" {} {}
20+
S: SUCCESS {"fields": ["2"], "qid": 2}
21+
{{
22+
C: PULL {"n": "*"}
23+
S: RECORD [1]
24+
SUCCESS {"has_more": true}
25+
{{
26+
C: PULL {"n": "*"}
27+
S: RECORD [1]
28+
----
29+
# Drivers that pipeline a PULL will takes this path in the discarding tests
30+
C: DISCARD {"n": "*"}
31+
}}
32+
----
33+
# Drivers that don't pipeline a PULL will takes this path in the discarding tests
34+
C: DISCARD {"n": "*"}
35+
}}
36+
S: SUCCESS {}
37+
{{
38+
C: PULL {"n": "*", "qid": 1}
39+
S: RECORD [1]
40+
----
41+
# Drivers that pipeline a PULL will takes this path in the discarding tests
42+
C: DISCARD {"n": "*", "qid": 1}
43+
}}
44+
S: SUCCESS {}
45+
C: COMMIT
46+
S: SUCCESS {"type": "w", "bookmark": "bookmark:1"}
47+
*: RESET
48+
?: GOODBYE

tests/stub/optimizations/test_optimizations.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,15 @@ def test():
258258
res.consume()
259259
else:
260260
res.next()
261+
res.next()
261262
tx.commit()
262263
else:
263264
res = session.run("CYPHER")
264265
if consume:
265266
res.consume()
266267
else:
267268
res.next()
269+
res.next()
268270

269271
session.close()
270272
driver.close()
@@ -282,3 +284,78 @@ def test():
282284
test()
283285
self._server.reset()
284286
self._router.reset()
287+
288+
@driver_feature(types.Feature.OPT_IMPLICIT_DEFAULT_ARGUMENTS)
289+
def test_uses_implicit_default_arguments_multi_query(self):
290+
def test():
291+
self._server.start(path=self.script_path(
292+
"v4x3", "all_default_multi_query.script"
293+
))
294+
auth = types.AuthorizationToken(scheme="basic", principal="neo4j",
295+
credentials="pass")
296+
driver = Driver(self._backend, "bolt://%s" % self._server.address,
297+
auth)
298+
session = driver.session("w") # write is default
299+
tx = session.beginTransaction()
300+
res = tx.run("CYPHER")
301+
if consume1:
302+
res.consume()
303+
else:
304+
res.next()
305+
res.next()
306+
res = tx.run("CYPHER")
307+
if consume2:
308+
res.consume()
309+
else:
310+
res.next()
311+
res.next()
312+
tx.commit()
313+
314+
session.close()
315+
driver.close()
316+
self._server.done()
317+
318+
for consume1 in (True, False):
319+
for consume2 in (True, False):
320+
with self.subTest(("discard1" if consume1 else "pull1")
321+
+ ("_discard2" if consume2 else "_pull2")):
322+
test()
323+
self._server.reset()
324+
self._router.reset()
325+
326+
@driver_feature(types.Feature.OPT_IMPLICIT_DEFAULT_ARGUMENTS)
327+
def test_uses_implicit_default_arguments_multi_query_nested(self):
328+
def test():
329+
self._server.start(path=self.script_path(
330+
"v4x3", "all_default_multi_query_nested.script"
331+
))
332+
auth = types.AuthorizationToken(scheme="basic", principal="neo4j",
333+
credentials="pass")
334+
driver = Driver(self._backend, "bolt://%s" % self._server.address,
335+
auth)
336+
session = driver.session("w") # write is default
337+
tx = session.beginTransaction()
338+
res1 = tx.run("CYPHER")
339+
res1.next()
340+
res2 = tx.run("CYPHER")
341+
if consume2:
342+
res2.consume()
343+
else:
344+
res2.next()
345+
res2.next()
346+
if consume1:
347+
res1.consume()
348+
else:
349+
res1.next()
350+
tx.commit()
351+
352+
session.close()
353+
driver.close()
354+
self._server.done()
355+
356+
for consume1 in (True, False):
357+
for consume2 in (True, False):
358+
with self.subTest(("discard1" if consume1 else "pull1")
359+
+ ("_discard2" if consume2 else "_pull2")):
360+
test()
361+
self._server.reset()

0 commit comments

Comments
 (0)