Skip to content

Define resolver in TS declarations #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/v1/internal/transaction-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/internal/transaction-executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
!: BOLT 1
!: AUTO RESET
!: AUTO PULL_ALL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
!: BOLT 1
!: AUTO INIT
!: AUTO RESET
!: AUTO PULL_ALL
Expand Down
10 changes: 10 additions & 0 deletions test/types/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions types/v1/driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ declare interface Config {
connectionTimeout?: number
disableLosslessIntegers?: boolean
logging?: LoggingConfig
resolver?: (address: string) => string[] | Promise<string[]>
}

declare type SessionMode = 'READ' | 'WRITE'
Expand Down