From a59553bd7f7cd1ae225aac5f9de7b828cb1d8bbf Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Tue, 14 Sep 2021 13:32:49 +0200 Subject: [PATCH] Add tests for omitting qid when possible --- .../scripts/v4x0/tx_pull_1_nested.script | 14 ++-- .../iteration/scripts/v4x0/tx_pull_2.script | 2 +- .../scripts/v4x3/all_default.script | 27 +++++-- .../v4x3/all_default_multi_query.script | 47 +++++++++++ .../all_default_multi_query_nested.script | 48 ++++++++++++ .../stub/optimizations/test_optimizations.py | 77 +++++++++++++++++++ 6 files changed, 202 insertions(+), 13 deletions(-) create mode 100644 tests/stub/optimizations/scripts/v4x3/all_default_multi_query.script create mode 100644 tests/stub/optimizations/scripts/v4x3/all_default_multi_query_nested.script diff --git a/tests/stub/iteration/scripts/v4x0/tx_pull_1_nested.script b/tests/stub/iteration/scripts/v4x0/tx_pull_1_nested.script index 93827e6a3..76ce8db71 100644 --- a/tests/stub/iteration/scripts/v4x0/tx_pull_1_nested.script +++ b/tests/stub/iteration/scripts/v4x0/tx_pull_1_nested.script @@ -5,25 +5,25 @@ A: HELLO {"{}": "*"} C: BEGIN {} S: SUCCESS {} C: RUN "CYPHER" {} {} - PULL {"n": 1} S: SUCCESS {"fields": ["x"], "qid": 1} - RECORD ["1_1"] +C: PULL {"n": 1, "[qid]": 1} +S: RECORD ["1_1"] SUCCESS {"has_more": true} C: RUN "CYPHER" {} {} - PULL {"n": 1} S: SUCCESS {"fields": ["x"], "qid": 2} - RECORD ["2_1"] +C: PULL {"n": 1, "[qid]": 2} +S: RECORD ["2_1"] SUCCESS {"has_more": true} -C: PULL {"n": 1, "qid": 2} +C: PULL {"n": 1, "[qid]": 2} S: RECORD ["2_2"] SUCCESS {} C: PULL {"n": 1, "qid": 1} S: RECORD ["1_2"] SUCCESS {} C: RUN "CYPHER" {} {} - PULL {"n": 1} S: SUCCESS {"fields": ["x"], "qid": 3} - RECORD ["3_1"] +C: PULL {"n": 1, "[qid]": 3} +S: RECORD ["3_1"] SUCCESS {} C: COMMIT S: SUCCESS {"bookmark": "bm"} diff --git a/tests/stub/iteration/scripts/v4x0/tx_pull_2.script b/tests/stub/iteration/scripts/v4x0/tx_pull_2.script index f077a50d1..f4c5397ce 100644 --- a/tests/stub/iteration/scripts/v4x0/tx_pull_2.script +++ b/tests/stub/iteration/scripts/v4x0/tx_pull_2.script @@ -10,7 +10,7 @@ C: PULL {"n": 2, "[qid]": 7} S: RECORD [1] RECORD [2] SUCCESS {"has_more": true} -C: PULL {"n": 2, "qid": 7} +C: PULL {"n": 2, "[qid]": 7} S: RECORD [3] SUCCESS {} C: COMMIT diff --git a/tests/stub/optimizations/scripts/v4x3/all_default.script b/tests/stub/optimizations/scripts/v4x3/all_default.script index 74faffdfa..7d1f02ed7 100644 --- a/tests/stub/optimizations/scripts/v4x3/all_default.script +++ b/tests/stub/optimizations/scripts/v4x3/all_default.script @@ -8,12 +8,21 @@ S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"} C: BEGIN {} S: SUCCESS {} C: RUN "*" {} {} - S: SUCCESS {"fields": ["1"]} + S: SUCCESS {"fields": ["1"], "qid": 1} {{ C: PULL {"n": "*"} S: RECORD [1] + SUCCESS {"has_more": true} + {{ + C: PULL {"n": "*"} + S: RECORD [1] + ---- + # Drivers that pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} + }} ---- - C: DISCARD {} + # Drivers that don't pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} }} S: SUCCESS {} C: COMMIT @@ -25,11 +34,19 @@ S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"} {{ C: PULL {"n": "*"} S: RECORD [1] + SUCCESS {"has_more": true} + {{ + C: PULL {"n": "*"} + S: RECORD [1] + ---- + # Drivers that pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} + }} ---- - C: DISCARD {} + # Drivers that don't pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} }} - S: RECORD [1] - SUCCESS {"type": "w", "bookmark": "bookmark:1"} + S: SUCCESS {"type": "w", "bookmark": "bookmark:1"} }} *: RESET ?: GOODBYE diff --git a/tests/stub/optimizations/scripts/v4x3/all_default_multi_query.script b/tests/stub/optimizations/scripts/v4x3/all_default_multi_query.script new file mode 100644 index 000000000..c445ae25f --- /dev/null +++ b/tests/stub/optimizations/scripts/v4x3/all_default_multi_query.script @@ -0,0 +1,47 @@ +!: BOLT 4.3 + +C: HELLO {"user_agent": "*", "scheme": "basic", "principal": "*", "credentials": "*"} +S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"} +*: RESET +C: BEGIN {} +S: SUCCESS {} +C: RUN "*" {} {} +S: SUCCESS {"fields": ["1"], "qid": 1} +{{ + C: PULL {"n": "*"} + S: RECORD [1] + SUCCESS {"has_more": true} + {{ + C: PULL {"n": "*"} + S: RECORD [1] + ---- + # Drivers that pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} + }} +---- + # Drivers that don't pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} +}} +S: SUCCESS {} +C: RUN "*" {} {} +S: SUCCESS {"fields": ["2"], "qid": 2} +{{ + C: PULL {"n": "*"} + S: RECORD [1] + SUCCESS {"has_more": true} + {{ + C: PULL {"n": "*"} + S: RECORD [1] + ---- + # Drivers that pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} + }} +---- + # Drivers that don't pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} +}} +S: SUCCESS {} +C: COMMIT +S: SUCCESS {"type": "w", "bookmark": "bookmark:1"} +*: RESET +?: GOODBYE diff --git a/tests/stub/optimizations/scripts/v4x3/all_default_multi_query_nested.script b/tests/stub/optimizations/scripts/v4x3/all_default_multi_query_nested.script new file mode 100644 index 000000000..2701af35b --- /dev/null +++ b/tests/stub/optimizations/scripts/v4x3/all_default_multi_query_nested.script @@ -0,0 +1,48 @@ +!: BOLT 4.3 + +C: HELLO {"user_agent": "*", "scheme": "basic", "principal": "*", "credentials": "*"} +S: SUCCESS {"server": "Neo4j/4.3.0", "connection_id": "example-connection-id:1"} +*: RESET +C: BEGIN {} +S: SUCCESS {} +C: RUN "*" {} {} +S: SUCCESS {"fields": ["1"], "qid": 1} +C: PULL {"n": "*"} +S: RECORD [1] + SUCCESS {"has_more": true} +{? + # Eager drivers might pull a record in advance + C: PULL {"n": "*"} + S: RECORD [1] + SUCCESS {"has_more": true} +?} +C: RUN "*" {} {} +S: SUCCESS {"fields": ["2"], "qid": 2} +{{ + C: PULL {"n": "*"} + S: RECORD [1] + SUCCESS {"has_more": true} + {{ + C: PULL {"n": "*"} + S: RECORD [1] + ---- + # Drivers that pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} + }} +---- + # Drivers that don't pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*"} +}} +S: SUCCESS {} +{{ + C: PULL {"n": "*", "qid": 1} + S: RECORD [1] +---- + # Drivers that pipeline a PULL will takes this path in the discarding tests + C: DISCARD {"n": "*", "qid": 1} +}} +S: SUCCESS {} +C: COMMIT +S: SUCCESS {"type": "w", "bookmark": "bookmark:1"} +*: RESET +?: GOODBYE diff --git a/tests/stub/optimizations/test_optimizations.py b/tests/stub/optimizations/test_optimizations.py index 2de263b95..ecf59362a 100644 --- a/tests/stub/optimizations/test_optimizations.py +++ b/tests/stub/optimizations/test_optimizations.py @@ -258,6 +258,7 @@ def test(): res.consume() else: res.next() + res.next() tx.commit() else: res = session.run("CYPHER") @@ -265,6 +266,7 @@ def test(): res.consume() else: res.next() + res.next() session.close() driver.close() @@ -282,3 +284,78 @@ def test(): test() self._server.reset() self._router.reset() + + @driver_feature(types.Feature.OPT_IMPLICIT_DEFAULT_ARGUMENTS) + def test_uses_implicit_default_arguments_multi_query(self): + def test(): + self._server.start(path=self.script_path( + "v4x3", "all_default_multi_query.script" + )) + auth = types.AuthorizationToken(scheme="basic", principal="neo4j", + credentials="pass") + driver = Driver(self._backend, "bolt://%s" % self._server.address, + auth) + session = driver.session("w") # write is default + tx = session.beginTransaction() + res = tx.run("CYPHER") + if consume1: + res.consume() + else: + res.next() + res.next() + res = tx.run("CYPHER") + if consume2: + res.consume() + else: + res.next() + res.next() + tx.commit() + + session.close() + driver.close() + self._server.done() + + for consume1 in (True, False): + for consume2 in (True, False): + with self.subTest(("discard1" if consume1 else "pull1") + + ("_discard2" if consume2 else "_pull2")): + test() + self._server.reset() + self._router.reset() + + @driver_feature(types.Feature.OPT_IMPLICIT_DEFAULT_ARGUMENTS) + def test_uses_implicit_default_arguments_multi_query_nested(self): + def test(): + self._server.start(path=self.script_path( + "v4x3", "all_default_multi_query_nested.script" + )) + auth = types.AuthorizationToken(scheme="basic", principal="neo4j", + credentials="pass") + driver = Driver(self._backend, "bolt://%s" % self._server.address, + auth) + session = driver.session("w") # write is default + tx = session.beginTransaction() + res1 = tx.run("CYPHER") + res1.next() + res2 = tx.run("CYPHER") + if consume2: + res2.consume() + else: + res2.next() + res2.next() + if consume1: + res1.consume() + else: + res1.next() + tx.commit() + + session.close() + driver.close() + self._server.done() + + for consume1 in (True, False): + for consume2 in (True, False): + with self.subTest(("discard1" if consume1 else "pull1") + + ("_discard2" if consume2 else "_pull2")): + test() + self._server.reset()