Skip to content

Commit 036f808

Browse files
committed
Merge branch 1.7 into 4.0
2 parents 8d014b2 + 2dd64d9 commit 036f808

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/internal/transaction-executor.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
* limitations under the License.
1818
*/
1919

20-
import { newError, SERVICE_UNAVAILABLE, SESSION_EXPIRED } from '../error'
20+
import {
21+
newError,
22+
Neo4jError,
23+
SERVICE_UNAVAILABLE,
24+
SESSION_EXPIRED
25+
} from '../error'
2126

2227
const DEFAULT_MAX_RETRY_TIME_MS = 30 * 1000 // 30 seconds
2328
const DEFAULT_INITIAL_RETRY_DELAY_MS = 1000 // 1 seconds
@@ -199,6 +204,7 @@ export default class TransactionExecutor {
199204
static _canRetryOn (error) {
200205
return (
201206
error &&
207+
error instanceof Neo4jError &&
202208
error.code &&
203209
(error.code === SERVICE_UNAVAILABLE ||
204210
error.code === SESSION_EXPIRED ||

test/internal/transaction-executor.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ describe('#unit TransactionExecutor', () => {
8080
await testNoRetryOnUnknownError([LOCKS_TERMINATED_ERROR], 1)
8181
})
8282

83+
it('should not retry when transaction work returns promise rejected with unknown error type', async () => {
84+
class MyTestError extends Error {
85+
constructor (message, code) {
86+
super(message)
87+
this.code = code
88+
}
89+
}
90+
91+
const error = new MyTestError('an unexpected error', 504)
92+
const executor = new TransactionExecutor()
93+
const realWork = () => Promise.reject(error)
94+
95+
await expectAsync(
96+
executor.execute(transactionCreator(), tx => realWork())
97+
).toBeRejectedWith(error)
98+
})
99+
83100
it('should stop retrying when time expires', async () => {
84101
let clock
85102
const usedTransactions = []

test/types/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ const driver1: Driver = driver('bolt://localhost:7687')
5757
const driver2: Driver = driver('bolt://localhost:7687', basicAuthToken1)
5858
const driver3: Driver = driver('bolt://localhost:7687', basicAuthToken1, config)
5959

60+
const address1 = 'db-1.internal:7687'
61+
const address2 = 'db-2.internal:7687'
62+
const driver4: Driver = driver(
63+
'bolt://localhost',
64+
auth.basic('neo4j', 'password'),
65+
{
66+
resolver: address => Promise.resolve([address1, address2])
67+
}
68+
)
69+
6070
const readMode1: string = session.READ
6171
const writeMode1: string = session.WRITE
6272

types/driver.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ declare interface Config {
5555
connectionTimeout?: number
5656
disableLosslessIntegers?: boolean
5757
logging?: LoggingConfig
58+
resolver?: (address: string) => string[] | Promise<string[]>
5859
}
5960

6061
declare type SessionMode = 'READ' | 'WRITE'

0 commit comments

Comments
 (0)