def __get_url_shorthands(self, configs): """ :type configs: list :return: list """ urls = [] for candidate in configs[:]: if is_url(candidate): urls.append(candidate) configs.remove(candidate) if urls: self.log.debug("Adding HTTP shorthand config for: %s", urls) config_fds = NamedTemporaryFile(prefix="http_", suffix=".yml") fname = config_fds.name config_fds.close() config = Configuration.from_dict({ "execution": [{ "concurrency": "${__tstFeedback(Throughput_Limiter,1,${__P(concurrencyCap,1)},2)}", "hold-for": "2m", "throughput": "${__P(throughput,600)}", "scenario": "linear-growth", }], "scenarios": { "linear-growth": { "retrieve-resources": False, "timeout": "5s", "keepalive": False, "requests": [{ "action": "pause", "pause-duration": 0, "jsr223": [{ "language": "javascript", "execute": "before", "script-text": """ var startTime = parseInt(props.get("startTime")); if (!startTime) { startTime = Math.floor((new Date()).getTime() / 1000); props.put("startTime", startTime); } else { var now = Math.floor((new Date()).getTime() / 1000); var offset = now - startTime; if (offset < 60) { var targetOffset = Math.max(offset * 10, 10); props.put("throughput", targetOffset.toString()); } }""" }] }] + urls, } }, "modules": { "jmeter": { "properties": { "throughput": 1, "concurrencyCap": 500, }, } } }) config.dump(fname, Configuration.JSON) return [fname] else: return []
def __get_url_shorthands(self, configs): """ :type configs: list :return: list """ urls = [] for candidate in configs[:]: if is_url(candidate): urls.append(candidate) configs.remove(candidate) if urls: self.log.debug("Adding HTTP shorthand config for: %s", urls) config_fds = NamedTemporaryFile(prefix="http_", suffix=".yml") fname = config_fds.name config_fds.close() config = Configuration.from_dict({ "execution": [{ "concurrency": "${__tstFeedback(Throughput_Limiter,1,${__P(concurrencyCap,1)},2)}", "hold-for": "2m", "throughput": "${__P(throughput,600)}", "scenario": "linear-growth", }], "scenarios": { "linear-growth": { "retrieve-resources": False, "timeout": "5s", "keepalive": False, "requests": [{ "action": "pause", "pause-duration": 0, "jsr223": [{ "language": "javascript", "execute": "before", "script-text": """ var startTime = parseInt(props.get("startTime")); if (!startTime) { startTime = Math.floor((new Date()).getTime() / 1000); props.put("startTime", startTime); } else { var now = Math.floor((new Date()).getTime() / 1000); var offset = now - startTime; if (offset < 60) { var targetOffset = Math.max(offset * 10, 10); props.put("throughput", targetOffset.toString()); } }""" }] }] + urls, } }, "modules": { "jmeter": { "properties": { "throughput": 1, "concurrencyCap": 500, }, } } }) config.dump(fname, Configuration.JSON) return [fname] else: return []