Skip to content

Commit 643ade5

Browse files
committed
Add a test for retries on unknown exceptions
1 parent fd2da6e commit 643ade5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/v1/internal/transaction-executor.js

Lines changed: 6 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, Neo4jError, 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

test/internal/transaction-executor.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ describe('TransactionExecutor', () => {
9191
testNoRetryOnUnknownError([LOCKS_TERMINATED_ERROR], 1, done)
9292
})
9393

94+
it('should not retry when transaction work returns promise rejected with unknown error type', async () => {
95+
class MyTestError extends Error {
96+
constructor (message, code) {
97+
super(message)
98+
this.code = code
99+
}
100+
}
101+
102+
const error = new MyTestError('an unexpected error', 504)
103+
const executor = new TransactionExecutor()
104+
const realWork = () => Promise.reject(error)
105+
106+
await expectAsync(
107+
executor.execute(transactionCreator(), tx => realWork())
108+
).toBeRejectedWith(error)
109+
})
110+
94111
it('should stop retrying when time expires', done => {
95112
const executor = new TransactionExecutor()
96113
const usedTransactions = []

0 commit comments

Comments
 (0)