From 643ade5207861118c6b0be8a5e96e12be26939f4 Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Mon, 30 Sep 2019 18:18:16 +0100 Subject: [PATCH 1/3] Add a test for retries on unknown exceptions --- src/v1/internal/transaction-executor.js | 7 ++++++- test/internal/transaction-executor.test.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/v1/internal/transaction-executor.js b/src/v1/internal/transaction-executor.js index cc307078a..6e6672c01 100644 --- a/src/v1/internal/transaction-executor.js +++ b/src/v1/internal/transaction-executor.js @@ -17,7 +17,12 @@ * limitations under the License. */ -import { newError, Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from '../error' +import { + newError, + Neo4jError, + SERVICE_UNAVAILABLE, + SESSION_EXPIRED +} from '../error' const DEFAULT_MAX_RETRY_TIME_MS = 30 * 1000 // 30 seconds const DEFAULT_INITIAL_RETRY_DELAY_MS = 1000 // 1 seconds diff --git a/test/internal/transaction-executor.test.js b/test/internal/transaction-executor.test.js index f4f6c929f..28b706bf0 100644 --- a/test/internal/transaction-executor.test.js +++ b/test/internal/transaction-executor.test.js @@ -91,6 +91,23 @@ describe('TransactionExecutor', () => { testNoRetryOnUnknownError([LOCKS_TERMINATED_ERROR], 1, done) }) + it('should not retry when transaction work returns promise rejected with unknown error type', async () => { + class MyTestError extends Error { + constructor (message, code) { + super(message) + this.code = code + } + } + + const error = new MyTestError('an unexpected error', 504) + const executor = new TransactionExecutor() + const realWork = () => Promise.reject(error) + + await expectAsync( + executor.execute(transactionCreator(), tx => realWork()) + ).toBeRejectedWith(error) + }) + it('should stop retrying when time expires', done => { const executor = new TransactionExecutor() const usedTransactions = [] From 2b36aaa31ad36ccd6e8fa66f00907cc2bd5c7a4d Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Mon, 30 Sep 2019 18:19:22 +0100 Subject: [PATCH 2/3] Add resolver definition to typescript declarations --- test/types/index.test.ts | 10 ++++++++++ types/v1/driver.d.ts | 1 + 2 files changed, 11 insertions(+) diff --git a/test/types/index.test.ts b/test/types/index.test.ts index 6ba5653cd..12579c7c4 100644 --- a/test/types/index.test.ts +++ b/test/types/index.test.ts @@ -25,6 +25,16 @@ const driver2: neo4j.Driver = neo4j.driver( neo4j.auth.basic('neo4j', 'password') ) +const address1 = 'db-1.internal:7687' +const address2 = 'db-2.internal:7687' +const driver3: neo4j.Driver = neo4j.driver( + 'bolt://localhost', + neo4j.auth.basic('neo4j', 'password'), + { + resolver: address => Promise.resolve([address1, address2]) + } +) + const sessionModeRead: string = neo4j.session.READ const sessionModeWrite: string = neo4j.session.WRITE diff --git a/types/v1/driver.d.ts b/types/v1/driver.d.ts index 3a18e493c..2b9199c3a 100644 --- a/types/v1/driver.d.ts +++ b/types/v1/driver.d.ts @@ -63,6 +63,7 @@ declare interface Config { connectionTimeout?: number disableLosslessIntegers?: boolean logging?: LoggingConfig + resolver?: (address: string) => string[] | Promise } declare type SessionMode = 'READ' | 'WRITE' From eaee1ab6452a30d89d37a228c555ab16198c7136 Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Tue, 1 Oct 2019 17:56:28 +0100 Subject: [PATCH 3/3] Fix bolt version for stub scripts that mimic older servers --- .../boltstub/acquire_endpoints_old_routing_procedure.script | 1 + test/resources/boltstub/rediscover_and_read_with_init.script | 1 + 2 files changed, 2 insertions(+) diff --git a/test/resources/boltstub/acquire_endpoints_old_routing_procedure.script b/test/resources/boltstub/acquire_endpoints_old_routing_procedure.script index 9846be014..2a9db896f 100644 --- a/test/resources/boltstub/acquire_endpoints_old_routing_procedure.script +++ b/test/resources/boltstub/acquire_endpoints_old_routing_procedure.script @@ -1,3 +1,4 @@ +!: BOLT 1 !: AUTO RESET !: AUTO PULL_ALL diff --git a/test/resources/boltstub/rediscover_and_read_with_init.script b/test/resources/boltstub/rediscover_and_read_with_init.script index c2ce54c6f..9c2c0245b 100644 --- a/test/resources/boltstub/rediscover_and_read_with_init.script +++ b/test/resources/boltstub/rediscover_and_read_with_init.script @@ -1,3 +1,4 @@ +!: BOLT 1 !: AUTO INIT !: AUTO RESET !: AUTO PULL_ALL