From 7ceb3b811aad4c59f8899dab90dc7c66da4b28c0 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Wed, 4 Aug 2021 14:19:51 +0200 Subject: [PATCH 1/3] Add tests for optimized RESETs on FAILURE --- .../scripts/v3/failure_on_begin.script | 26 +++++++++++++ .../scripts/v3/failure_on_pull.script | 23 +++++++++++ .../scripts/v3/failure_on_run.script | 26 +++++++++++++ .../scripts/v4x3/failure_on_begin.script | 26 +++++++++++++ .../scripts/v4x3/failure_on_pull.script | 23 +++++++++++ .../scripts/v4x3/failure_on_run.script | 26 +++++++++++++ .../stub/optimizations/test_optimizations.py | 39 +++++++++++++++++++ 7 files changed, 189 insertions(+) create mode 100644 tests/stub/optimizations/scripts/v3/failure_on_begin.script create mode 100644 tests/stub/optimizations/scripts/v3/failure_on_pull.script create mode 100644 tests/stub/optimizations/scripts/v3/failure_on_run.script create mode 100644 tests/stub/optimizations/scripts/v4x3/failure_on_begin.script create mode 100644 tests/stub/optimizations/scripts/v4x3/failure_on_pull.script create mode 100644 tests/stub/optimizations/scripts/v4x3/failure_on_run.script diff --git a/tests/stub/optimizations/scripts/v3/failure_on_begin.script b/tests/stub/optimizations/scripts/v3/failure_on_begin.script new file mode 100644 index 000000000..87f105e9a --- /dev/null +++ b/tests/stub/optimizations/scripts/v3/failure_on_begin.script @@ -0,0 +1,26 @@ +!: BOLT 4.3 +!: AUTO HELLO + +{* + C: RESET + S: SUCCESS {} +*} +C: BEGIN "*" +S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."} +{? + # for pipelining driver + C: RUN "*" "*" "*" + S: IGNORED + {? + C: PULL_ALL + S: IGNORED + ?} +?} +{+ + C: RESET + S: SUCCESS {} ++} +{? + C: GOODBYE + S: +?} diff --git a/tests/stub/optimizations/scripts/v3/failure_on_pull.script b/tests/stub/optimizations/scripts/v3/failure_on_pull.script new file mode 100644 index 000000000..bb5ef7a10 --- /dev/null +++ b/tests/stub/optimizations/scripts/v3/failure_on_pull.script @@ -0,0 +1,23 @@ +!: BOLT 4.3 +!: AUTO HELLO + +{* + C: RESET + S: SUCCESS {} +*} +{? + C: BEGIN "*" + S: SUCCESS {} +?} +C: RUN "*" "*" "*" +S: SUCCESS {"fields": ["n"]} +C: PULL_ALL +S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."} +{+ + C: RESET + S: SUCCESS {} ++} +{? + C: GOODBYE + S: +?} diff --git a/tests/stub/optimizations/scripts/v3/failure_on_run.script b/tests/stub/optimizations/scripts/v3/failure_on_run.script new file mode 100644 index 000000000..3c3b003d5 --- /dev/null +++ b/tests/stub/optimizations/scripts/v3/failure_on_run.script @@ -0,0 +1,26 @@ +!: BOLT 4.3 +!: AUTO HELLO + +{* + C: RESET + S: SUCCESS {} +*} +{? + C: BEGIN "*" + S: SUCCESS {} +?} +C: RUN "*" "*" "*" +S: FAILURE {"code": "Neo.ClientError.Statement.SyntaxError", "message": "Git gud!"} +{? + # for pipelining driver + C: PULL_ALL + S: IGNORED +?} +{+ + C: RESET + S: SUCCESS {} ++} +{? + C: GOODBYE + S: +?} diff --git a/tests/stub/optimizations/scripts/v4x3/failure_on_begin.script b/tests/stub/optimizations/scripts/v4x3/failure_on_begin.script new file mode 100644 index 000000000..cb2107f2d --- /dev/null +++ b/tests/stub/optimizations/scripts/v4x3/failure_on_begin.script @@ -0,0 +1,26 @@ +!: BOLT 4.3 +!: AUTO HELLO + +{* + C: RESET + S: SUCCESS {} +*} +C: BEGIN "*" +S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."} +{? + # for pipelining driver + C: RUN "*" "*" "*" + S: IGNORED + {? + C: PULL "*" + S: IGNORED + ?} +?} +{+ + C: RESET + S: SUCCESS {} ++} +{? + C: GOODBYE + S: +?} diff --git a/tests/stub/optimizations/scripts/v4x3/failure_on_pull.script b/tests/stub/optimizations/scripts/v4x3/failure_on_pull.script new file mode 100644 index 000000000..b400ccfc7 --- /dev/null +++ b/tests/stub/optimizations/scripts/v4x3/failure_on_pull.script @@ -0,0 +1,23 @@ +!: BOLT 4.3 +!: AUTO HELLO + +{* + C: RESET + S: SUCCESS {} +*} +{? + C: BEGIN "*" + S: SUCCESS {} +?} +C: RUN "*" "*" "*" +S: SUCCESS {"fields": ["n"]} +C: PULL "*" +S: FAILURE {"code": "Neo.ClientError.MadeUp.Code", "message": "Something went wrong..."} +{+ + C: RESET + S: SUCCESS {} ++} +{? + C: GOODBYE + S: +?} diff --git a/tests/stub/optimizations/scripts/v4x3/failure_on_run.script b/tests/stub/optimizations/scripts/v4x3/failure_on_run.script new file mode 100644 index 000000000..cf35858f7 --- /dev/null +++ b/tests/stub/optimizations/scripts/v4x3/failure_on_run.script @@ -0,0 +1,26 @@ +!: BOLT 4.3 +!: AUTO HELLO + +{* + C: RESET + S: SUCCESS {} +*} +{? + C: BEGIN "*" + S: SUCCESS {} +?} +C: RUN "*" "*" "*" +S: FAILURE {"code": "Neo.ClientError.Statement.SyntaxError", "message": "Git gud!"} +{? + # for pipelining driver + C: PULL "*" + S: IGNORED +?} +{+ + C: RESET + S: SUCCESS {} ++} +{? + C: GOODBYE + S: +?} diff --git a/tests/stub/optimizations/test_optimizations.py b/tests/stub/optimizations/test_optimizations.py index 30a4789e4..12a906d5e 100644 --- a/tests/stub/optimizations/test_optimizations.py +++ b/tests/stub/optimizations/test_optimizations.py @@ -173,6 +173,45 @@ def test_no_reset_on_clean_connection(self): check_no_reset=True) self._server.reset() + @driver_feature(types.Feature.OPT_MINIMAL_RESETS) + def test_exactly_one_reset_on_failure(self): + def test(): + script_path = self.script_path( + "v4x3", "failure_on_{}.script".format(fail_on) + ) + self._server.start(path=script_path) + auth = types.AuthorizationToken(scheme="basic", principal="neo4j", + credentials="pass") + driver = Driver(self._backend, "bolt://%s" % self._server.address, + auth) + session = driver.session("w") + if use_tx: + with self.assertRaises(types.DriverError): + tx = session.beginTransaction() + res = tx.run("CYPHER") + res.next() + else: + with self.assertRaises(types.DriverError): + res = session.run("CYPHER") + res.next() + session.close() + driver.close() + self._server.done() + reset_count = self._server.count_requests("RESET") + self._server._dump() + self.assertEqual(reset_count, 1) + + for version in ("v3", "v4x3")[:1]: + for use_tx in (False, True)[:1]: + for fail_on in ("pull", "run", "begin")[1:2]: + if fail_on == "begin" and not use_tx: + continue + with self.subTest(version + + ("_tx" if use_tx else "_autocommit") + + "_{}".format(fail_on)): + test() + self._server.reset() + @driver_feature(types.Feature.OPT_IMPLICIT_DEFAULT_ARGUMENTS) def test_uses_implicit_default_arguments(self): def test(): From 41a242346bc8394a57898f70969669db59ffb656 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 5 Aug 2021 11:58:33 +0200 Subject: [PATCH 2/3] Fix bolt version in StubScripts --- tests/stub/optimizations/scripts/v3/failure_on_begin.script | 2 +- tests/stub/optimizations/scripts/v3/failure_on_pull.script | 2 +- tests/stub/optimizations/scripts/v3/failure_on_run.script | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/stub/optimizations/scripts/v3/failure_on_begin.script b/tests/stub/optimizations/scripts/v3/failure_on_begin.script index 87f105e9a..37b970ddd 100644 --- a/tests/stub/optimizations/scripts/v3/failure_on_begin.script +++ b/tests/stub/optimizations/scripts/v3/failure_on_begin.script @@ -1,4 +1,4 @@ -!: BOLT 4.3 +!: BOLT 3 !: AUTO HELLO {* diff --git a/tests/stub/optimizations/scripts/v3/failure_on_pull.script b/tests/stub/optimizations/scripts/v3/failure_on_pull.script index bb5ef7a10..0f720244e 100644 --- a/tests/stub/optimizations/scripts/v3/failure_on_pull.script +++ b/tests/stub/optimizations/scripts/v3/failure_on_pull.script @@ -1,4 +1,4 @@ -!: BOLT 4.3 +!: BOLT 3 !: AUTO HELLO {* diff --git a/tests/stub/optimizations/scripts/v3/failure_on_run.script b/tests/stub/optimizations/scripts/v3/failure_on_run.script index 3c3b003d5..ef1002d62 100644 --- a/tests/stub/optimizations/scripts/v3/failure_on_run.script +++ b/tests/stub/optimizations/scripts/v3/failure_on_run.script @@ -1,4 +1,4 @@ -!: BOLT 4.3 +!: BOLT 3 !: AUTO HELLO {* From 031b30fc731ba6792bc4f9c86e71e88146ee39c7 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 5 Aug 2021 12:03:30 +0200 Subject: [PATCH 3/3] Remove debug code --- tests/stub/optimizations/test_optimizations.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/stub/optimizations/test_optimizations.py b/tests/stub/optimizations/test_optimizations.py index 12a906d5e..a79be35d4 100644 --- a/tests/stub/optimizations/test_optimizations.py +++ b/tests/stub/optimizations/test_optimizations.py @@ -177,7 +177,7 @@ def test_no_reset_on_clean_connection(self): def test_exactly_one_reset_on_failure(self): def test(): script_path = self.script_path( - "v4x3", "failure_on_{}.script".format(fail_on) + version, "failure_on_{}.script".format(fail_on) ) self._server.start(path=script_path) auth = types.AuthorizationToken(scheme="basic", principal="neo4j", @@ -198,12 +198,11 @@ def test(): driver.close() self._server.done() reset_count = self._server.count_requests("RESET") - self._server._dump() self.assertEqual(reset_count, 1) - for version in ("v3", "v4x3")[:1]: - for use_tx in (False, True)[:1]: - for fail_on in ("pull", "run", "begin")[1:2]: + for version in ("v3", "v4x3"): + for use_tx in (False, True): + for fail_on in ("pull", "run", "begin"): if fail_on == "begin" and not use_tx: continue with self.subTest(version