UNPKG

@gatling.io/core

Version:

Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).

92 lines (91 loc) 4.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pauseImpl = exports.toJvmPauseType = void 0; const jvm_types_1 = require("@gatling.io/jvm-types"); const duration_1 = require("../utils/duration"); const session_1 = require("../session"); const isPauseType = (x) => x === "Disabled" || x === "Constant" || x === "Exponential" || typeof x.type === "string"; const toJvmPauseType = (pauseType) => { if (pauseType === "Disabled") { // FIXME find better solution for generating static field definitions in java2typescript (without conflicting // with methods of the same name, e.g. 'JvmHttpDsl.http' vs. 'JvmHttpDsl.http(String)') return jvm_types_1.CoreDsl.disabledPauses; } else if (pauseType === "Constant") { return jvm_types_1.CoreDsl.constantPauses; } else if (pauseType === "Exponential") { return jvm_types_1.CoreDsl.exponentialPauses; } else if (pauseType.type === "NormalWithPercentageDuration") { return jvm_types_1.CoreDsl.normalPausesWithPercentageDuration(pauseType.stdDev); } else if (pauseType.type === "NormalWithStdDevDuration") { return jvm_types_1.CoreDsl.normalPausesWithStdDevDuration((0, duration_1.toJvmDuration)(pauseType.stdDev)); } else if (pauseType.type === "Custom") { return jvm_types_1.CoreDsl.customPauses((0, session_1.underlyingSessionTo)(pauseType.f)); } else if (pauseType.type === "UniformPercentage") { return jvm_types_1.CoreDsl.uniformPausesPlusOrMinusPercentage(pauseType.plusOrMinus); } else if (pauseType.type === "UniformDuration") { return jvm_types_1.CoreDsl.uniformPausesPlusOrMinusDuration((0, duration_1.toJvmDuration)(pauseType.plusOrMinus)); } throw Error(`Unhandled pause type ${pauseType}`); }; exports.toJvmPauseType = toJvmPauseType; const pauseImpl = (jvmGroups, wrap) => (arg0, arg1, arg2) => { if (arg2 !== undefined) { // pause(min, max, pauseType) if (typeof arg0 === "string" && typeof arg1 === "string") { return wrap(jvmGroups.pause(arg0, arg1, (0, exports.toJvmPauseType)(arg2))); } else if (typeof arg0 === "function" && typeof arg1 === "function") { return wrap(jvmGroups.pause((0, session_1.underlyingSessionToDuration)(arg0), (0, session_1.underlyingSessionToDuration)(arg1), (0, exports.toJvmPauseType)(arg2))); } else if ((0, duration_1.isDuration)(arg0) && (0, duration_1.isDuration)(arg1)) { return wrap(jvmGroups.pause((0, duration_1.toJvmDuration)(arg0), (0, duration_1.toJvmDuration)(arg1), (0, exports.toJvmPauseType)(arg2))); } } else if (arg1 !== undefined) { if (isPauseType(arg1)) { // pause(duration, pauseType) if (typeof arg0 === "string") { return wrap(jvmGroups.pause(arg0, (0, exports.toJvmPauseType)(arg1))); } else if (typeof arg0 === "function") { return wrap(jvmGroups.pause((0, session_1.underlyingSessionToDuration)(arg0), (0, exports.toJvmPauseType)(arg1))); } else if ((0, duration_1.isDuration)(arg0)) { return wrap(jvmGroups.pause((0, duration_1.toJvmDuration)(arg0), (0, exports.toJvmPauseType)(arg1))); } } else { // pause(min, max) if (typeof arg0 === "string" && typeof arg1 === "string") { return wrap(jvmGroups.pause(arg0, arg1)); } else if (typeof arg0 === "function" && typeof arg1 === "function") { return wrap(jvmGroups.pause((0, session_1.underlyingSessionToDuration)(arg0), (0, session_1.underlyingSessionToDuration)(arg1))); } else if ((0, duration_1.isDuration)(arg0) && (0, duration_1.isDuration)(arg1)) { return wrap(jvmGroups.pause((0, duration_1.toJvmDuration)(arg0), (0, duration_1.toJvmDuration)(arg1))); } } } else { // pause(duration) if (typeof arg0 === "string") { return wrap(jvmGroups.pause(arg0)); } else if (typeof arg0 === "function") { return wrap(jvmGroups.pause((0, session_1.underlyingSessionToDuration)(arg0))); } else if ((0, duration_1.isDuration)(arg0)) { return wrap(jvmGroups.pause((0, duration_1.toJvmDuration)(arg0))); } } throw Error(`pause() called with invalid arguments ${arg0}, ${arg1}, ${arg2}`); }; exports.pauseImpl = pauseImpl;