UNPKG

dockest

Version:

Dockest is an integration testing tool aimed at alleviating the process of evaluating unit tests whilst running multi-container Docker applications.

28 lines 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withRetry = void 0; const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const errors_1 = require("../errors"); const LOG_PREFIX = '[Readiness Retry]'; /** * Retry a readiness check for the specified amount before failing/succeeding. */ const withRetry = (input, opts) => (args) => { return (0, rxjs_1.of)(input).pipe((0, operators_1.mergeMap)((readinessCheck) => (0, rxjs_1.from)(readinessCheck(args))), (0, operators_1.retryWhen)((errors) => { let retries = 0; return errors.pipe((0, operators_1.tap)((value) => { retries = retries + 1; args.runner.logger.warn(`${LOG_PREFIX} Error: ${value.message}`); args.runner.logger.debug(`${LOG_PREFIX} Timeout after ${opts.retryCount - retries} retries (Retry count set to ${opts.retryCount}). `); }), (0, operators_1.takeWhile)(() => { if (retries < opts.retryCount) { return true; } throw new errors_1.DockestError(`${LOG_PREFIX} Timed out`, { runner: args.runner }); }), (0, operators_1.delay)(1000)); })); }; exports.withRetry = withRetry; //# sourceMappingURL=with-retry.js.map