From 7bb16cdd942c3f80f7f573f22bd311be7ed65fa8 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Thu, 13 Apr 2023 16:31:54 +0300 Subject: [PATCH] [#49] Import and use k6-utils library for uuidv4 Signed-off-by: Alejandro Lopez --- examples/local.js | 2 +- examples/native.js | 4 ++-- examples/native_onsite.js | 2 +- examples/s3.js | 4 ++-- examples/s3local.js | 2 +- scenarios/grpc.js | 8 +------- scenarios/http.js | 8 +------- scenarios/libs/k6-utils-1.4.0.js | 2 ++ scenarios/local.js | 8 +------- scenarios/s3.js | 8 +------- scenarios/s3local.js | 9 +-------- 11 files changed, 14 insertions(+), 43 deletions(-) create mode 100644 scenarios/libs/k6-utils-1.4.0.js diff --git a/examples/local.js b/examples/local.js index 320c89b..766f2e2 100644 --- a/examples/local.js +++ b/examples/local.js @@ -1,5 +1,5 @@ -import {uuidv4} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; import local from 'k6/x/frostfs/local'; +import { uuidv4 } from '../scenarios/libs/k6-utils-1.4.0.js'; const payload = open('../go.sum', 'b'); const local_cli = local.connect("/path/to/config.yaml", "") diff --git a/examples/native.js b/examples/native.js index 45bb5fc..1b9ad26 100644 --- a/examples/native.js +++ b/examples/native.js @@ -1,6 +1,6 @@ -import {uuidv4} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; -import {fail} from "k6"; import native from 'k6/x/frostfs/native'; +import { fail } from "k6"; +import { uuidv4 } from '../scenarios/libs/k6-utils-1.4.0.js'; const payload = open('../go.sum', 'b'); const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb", 0, 0) diff --git a/examples/native_onsite.js b/examples/native_onsite.js index 0ef6ce7..218b7e2 100644 --- a/examples/native_onsite.js +++ b/examples/native_onsite.js @@ -1,5 +1,5 @@ -import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; import native from 'k6/x/frostfs/native'; +import { uuidv4 } from '../scenarios/libs/k6-utils-1.4.0.js'; const payload = open('../go.sum', 'b'); const container = "AjSxSNNXbJUDPqqKYm1VbFVDGCakbpUNH8aGjPmGAH3B" diff --git a/examples/s3.js b/examples/s3.js index 1ee1431..6e73ec6 100644 --- a/examples/s3.js +++ b/examples/s3.js @@ -1,6 +1,6 @@ -import {uuidv4} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; -import {fail} from 'k6' import s3 from 'k6/x/frostfs/s3'; +import { fail } from 'k6' +import { uuidv4 } from '../scenarios/libs/k6-utils-1.4.0.js'; const payload = open('../go.sum', 'b'); const bucket = "cats" diff --git a/examples/s3local.js b/examples/s3local.js index 830e510..c4d3ac8 100644 --- a/examples/s3local.js +++ b/examples/s3local.js @@ -1,5 +1,5 @@ -import {uuidv4} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; import s3local from 'k6/x/frostfs/s3local'; +import { uuidv4 } from '../scenarios/libs/k6-utils-1.4.0.js'; const bucket = "testbucket" const payload = open('../go.sum', 'b'); diff --git a/scenarios/grpc.js b/scenarios/grpc.js index 19a975a..5719d5f 100644 --- a/scenarios/grpc.js +++ b/scenarios/grpc.js @@ -6,6 +6,7 @@ import { SharedArray } from 'k6/data'; import { sleep } from 'k6'; import { textSummary } from './libs/k6-summary-0.0.2.js'; import { parseEnv } from './libs/env-parser.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); @@ -170,10 +171,3 @@ export function obj_delete() { obj_registry.deleteObject(obj.id); } - -export function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} diff --git a/scenarios/http.js b/scenarios/http.js index 45cc627..2863fde 100644 --- a/scenarios/http.js +++ b/scenarios/http.js @@ -6,6 +6,7 @@ import { SharedArray } from 'k6/data'; import { sleep } from 'k6'; import { textSummary } from './libs/k6-summary-0.0.2.js'; import { parseEnv } from './libs/env-parser.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); @@ -120,10 +121,3 @@ export function obj_read() { log.withFields({status: resp.status, cid: obj.container, oid: obj.object}).error(resp.error); } } - -export function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} diff --git a/scenarios/libs/k6-utils-1.4.0.js b/scenarios/libs/k6-utils-1.4.0.js new file mode 100644 index 0000000..9545b56 --- /dev/null +++ b/scenarios/libs/k6-utils-1.4.0.js @@ -0,0 +1,2 @@ +(()=>{"use strict";var t={n:r=>{var e=r&&r.__esModule?()=>r.default:()=>r;return t.d(e,{a:e}),e},d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};t.r(r),t.d(r,{findBetween:()=>x,getCurrentStageIndex:()=>i,normalDistributionStages:()=>m,parseDuration:()=>o,randomIntBetween:()=>d,randomItem:()=>h,randomString:()=>p,tagWithCurrentStageIndex:()=>u,tagWithCurrentStageProfile:()=>s,uuidv4:()=>g});const e=require("k6/execution");var n=t.n(e);function o(t){if(null==t||t.length<1)throw new Error("str is empty");for(var r=0,e="",n={},o=0;o0&&(r+=parseFloat(e,10)),r}function a(t){return t>="0"&&t<="9"}function i(){if(null==n()||null==n().test||null==n().test.options)throw new Error("k6/execution.test.options is undefined - getCurrentStageIndex requires a k6 v0.38.0 or later. Please, upgrade for getting k6/execution.test.options supported.");var t=n().test.options.scenarios[n().scenario.name];if(null==t)throw new Error("the exec.test.options object doesn't contain the current scenario ".concat(n().scenario.name));if(null==t.stages)throw new Error("only ramping-vus or ramping-arravial-rate supports stages, it is not possible to get a stage index on other executors.");if(t.stages.length<1)throw new Error("the current scenario ".concat(t.name," doesn't contain any stage"));for(var r=0,e=new Date-n().scenario.startTime,a=0;ao.target?"ramp-up":o.target==e.target?"steady":"ramp-down"}()}const l=require("k6/crypto");function c(t){return function(t){if(Array.isArray(t))return f(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return f(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return f(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e0&&void 0!==arguments[0]&&arguments[0];return t?y():v()}function d(t,r){return Math.floor(Math.random()*(r-t+1)+t)}function h(t){return t[Math.floor(Math.random()*t.length)]}function p(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"abcdefghijklmnopqrstuvwxyz",e="";t--;)e+=r[Math.random()*r.length|0];return e}function x(t,r,e){for(var n,o=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=[],i=!0,u=0;i&&-1!=(n=t.indexOf(r))&&(n+=r.length,-1!=(u=t.indexOf(e,n)));){var s=t.substring(n,u);if(!o)return s;a.push(s),t=t.substring(u+e.length)}return a.length?a:null}function m(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10;function n(t,r,e){return Math.exp(-.5*Math.pow((e-t)/r,2))/(r*Math.sqrt(2*Math.PI))}for(var o=0,a=1,i=new Array(e+2).fill(0),u=new Array(e+2).fill(Math.ceil(r/6)),s=[],l=0;l<=e;l++)i[l]=n(o,a,-2*a+4*a*l/e);for(var f=Math.max.apply(Math,c(i)),g=i.map((function(r){return Math.round(r*t/f)})),d=1;d<=e;d++)u[d]=Math.ceil(4*r/(6*e));for(var h=0;h<=e+1;h++)s.push({duration:"".concat(u[h],"s"),target:g[h]});return s}function v(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var r=16*Math.random()|0;return("x"===t?r:3&r|8).toString(16)}))}function y(){for(var t=[],r=0;r<256;++r)t.push((r+256).toString(16).slice(1));var e=new Uint8Array((0,l.randomBytes)(16));return e[6]=15&e[6]|64,e[8]=63&e[8]|128,(t[e[0]]+t[e[1]]+t[e[2]]+t[e[3]]+"-"+t[e[4]]+t[e[5]]+"-"+t[e[6]]+t[e[7]]+"-"+t[e[8]]+t[e[9]]+"-"+t[e[10]]+t[e[11]]+t[e[12]]+t[e[13]]+t[e[14]]+t[e[15]]).toLowerCase()}var w=exports;for(var b in r)w[b]=r[b];r.__esModule&&Object.defineProperty(w,"__esModule",{value:!0})})(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/scenarios/local.js b/scenarios/local.js index 7254419..2c695e3 100644 --- a/scenarios/local.js +++ b/scenarios/local.js @@ -5,6 +5,7 @@ import registry from 'k6/x/frostfs/registry'; import { SharedArray } from 'k6/data'; import { textSummary } from './libs/k6-summary-0.0.2.js'; import { parseEnv } from './libs/env-parser.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); @@ -154,10 +155,3 @@ export function obj_delete() { obj_registry.deleteObject(obj.id); } - -export function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} diff --git a/scenarios/s3.js b/scenarios/s3.js index 0694932..2ca696c 100644 --- a/scenarios/s3.js +++ b/scenarios/s3.js @@ -6,6 +6,7 @@ import { SharedArray } from 'k6/data'; import { sleep } from 'k6'; import { textSummary } from './libs/k6-summary-0.0.2.js'; import { parseEnv } from './libs/env-parser.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); @@ -167,10 +168,3 @@ export function obj_delete() { obj_registry.deleteObject(obj.id); } - -export function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} diff --git a/scenarios/s3local.js b/scenarios/s3local.js index 8dcb75a..b227e1e 100644 --- a/scenarios/s3local.js +++ b/scenarios/s3local.js @@ -5,6 +5,7 @@ import s3local from 'k6/x/frostfs/s3local'; import { SharedArray } from 'k6/data'; import { textSummary } from './libs/k6-summary-0.0.2.js'; import { parseEnv } from './libs/env-parser.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); @@ -122,11 +123,3 @@ export function obj_read() { log.withFields({bucket: obj.bucket, key: obj.object}).error(resp.error); } } - -export function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} -