Add follow tests

This commit is contained in:
Chocobozzz 2017-11-21 13:43:29 +01:00
parent 81de19482b
commit 0f91ae62df
No known key found for this signature in database
GPG key ID: 583A612D890159BE
23 changed files with 736 additions and 522 deletions

View file

@ -4,12 +4,15 @@ import * as Bluebird from 'bluebird'
import { logger } from './logger'
type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] }
function retryTransactionWrapper (functionToRetry: (...args) => Promise<any> | Bluebird<any>, options: RetryTransactionWrapperOptions) {
function retryTransactionWrapper <T> (
functionToRetry: (...args) => Promise<T> | Bluebird<T>,
options: RetryTransactionWrapperOptions
): Promise<T> {
const args = options.arguments ? options.arguments : []
return transactionRetryer(callback => {
return transactionRetryer<T>(callback => {
functionToRetry.apply(this, args)
.then(result => callback(null, result))
.then((result: T) => callback(null, result))
.catch(err => callback(err))
})
.catch(err => {
@ -18,8 +21,8 @@ function retryTransactionWrapper (functionToRetry: (...args) => Promise<any> | B
})
}
function transactionRetryer (func: Function) {
return new Promise((res, rej) => {
function transactionRetryer <T> (func: (err: any, data: T) => any) {
return new Promise<T>((res, rej) => {
retry({
times: 5,