feat: initial commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import http from 'k6/http';
|
||||
import { sleep } from 'k6';
|
||||
|
||||
export default function () {
|
||||
http.get('https://test.k6.io');
|
||||
sleep(1);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
let k6 = require("k6");
|
||||
let utils = require("./utils.js");
|
||||
|
||||
let modules = [];
|
||||
let datas = [];
|
||||
let splitFiles = __ENV.PIVOT_FILE.split("*");
|
||||
|
||||
for (let i = 0; i < splitFiles.length; i++) {
|
||||
let file = "/testRunner/tests/BestPracticeWorkbook/" + splitFiles[i];
|
||||
let fileText = "";
|
||||
if (!String(file).endsWith(".json")) {
|
||||
modules[file] = require(file);
|
||||
} else {
|
||||
fileText = open(file).replace(/(\r\n|\n|\r)/gm, "");
|
||||
}
|
||||
|
||||
datas.push({ fileName: file, text: fileText });
|
||||
}
|
||||
|
||||
module.exports.options = {
|
||||
teardownTimeout: "2m0s",
|
||||
stages: [
|
||||
// { duration: "0m0s", target: 1 },
|
||||
// { duration: "0m10s", target: 1 },
|
||||
// { duration: "0m0s", target: 5 },
|
||||
// { duration: "3m0s", target: 5 },
|
||||
// { duration: "0m0s", target: 10 },
|
||||
// { duration: "3m0s", target: 10 },
|
||||
// { duration: "0m0s", target: 20 },
|
||||
// { duration: "3m0s", target: 20 },
|
||||
// { duration: "0m0s", target: 30 },
|
||||
// { duration: "3m0s", target: 30},
|
||||
// { duration: "0m0s", target: 40 },
|
||||
// { duration: "3m0s", target: 40 },
|
||||
// { duration: "0m0s", target: 50 },
|
||||
// { duration: "3m0s", target: 50 },
|
||||
// { duration: "0m0s", target: 75 },
|
||||
// { duration: "5m0s", target: 75 },
|
||||
// { duration: "0m0s", target: 100 },
|
||||
// { duration: "5m0s", target: 100 },
|
||||
// { duration: "0m0s", target: 150 },
|
||||
// { duration: "5m0s", target: 150 },
|
||||
// { duration: "0m0s", target: 200 },
|
||||
// { duration: "5m0s", target: 200 },
|
||||
// { duration: "0m0s", target: 250 },
|
||||
// { duration: "5m0s", target: 250 },
|
||||
// { duration: "0m0s", target: 300 },
|
||||
// { duration: "5m0s", target: 300 },
|
||||
// { duration: "0m0s", target: 350 },
|
||||
// { duration: "5m0s", target: 350 },
|
||||
{ duration: "0m0s", target: 450 },
|
||||
{ duration: "5m0s", target: 450 },
|
||||
{ duration: "0m0s", target: 550 },
|
||||
{ duration: "5m0s", target: 550 },
|
||||
{ duration: "0m0s", target: 650 },
|
||||
{ duration: "5m0s", target: 650 },
|
||||
{ duration: "0m0s", target: 750 },
|
||||
{ duration: "5m0s", target: 750 },
|
||||
{ duration: "0m0s", target: 850 },
|
||||
{ duration: "5m0s", target: 850 },
|
||||
{ duration: "0m0s", target: 1000 },
|
||||
{ duration: "5m0s", target: 1000 },
|
||||
{ duration: "0m0s", target: 1500 },
|
||||
{ duration: "5m0s", target: 1500 },
|
||||
{ duration: "0m0s", target: 2000 },
|
||||
{ duration: "5m0s", target: 2000 },
|
||||
],
|
||||
};
|
||||
|
||||
export function setup() {
|
||||
console.log("setting up token");
|
||||
return utils.generateToken();
|
||||
}
|
||||
|
||||
module.exports.default = function run(token) {
|
||||
let clone = [];
|
||||
Object.assign(clone, datas);
|
||||
|
||||
while (clone.length > 0) {
|
||||
let ran = Math.floor(Math.random() * clone.length);
|
||||
let currentItems = clone.splice(ran, Math.floor(Math.random() * 3 + 1));
|
||||
|
||||
k6.sleep(Math.round(Math.random() * 20 + 1));
|
||||
|
||||
for (let i = 0; i < currentItems.length; i++) {
|
||||
k6.group(currentItems[i].fileName.substring(7), function () {
|
||||
utils.runHttp(currentItems[i], token);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
const http = require("k6/http");
|
||||
const isLogging = false;
|
||||
|
||||
export function runHttp(jsonBlob, token) {
|
||||
let response;
|
||||
if (isLogging) console.log("running file: ", jsonBlob.fileName)
|
||||
let json = JSON.stringify(jsonBlob.text);
|
||||
|
||||
const startDay = Math.floor(Math.random() * 30) + 1;
|
||||
const endDay = Math.floor(Math.random() * 30) + 1;
|
||||
json = json.replace("{startDay}", startDay);
|
||||
json = json.replace("{endDay}", endDay);
|
||||
json = JSON.parse(json);
|
||||
response = http.post(
|
||||
'https://analytics-api-perf.dev.stratanetwork.net/api/v1/data-sources/1307/query',
|
||||
json,
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
Accept: '*/*',
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"Clientappname": 'strata-analytics',
|
||||
'content-type': 'application/json',
|
||||
'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
},
|
||||
}
|
||||
)
|
||||
if(response.status !== 200) console.log("endpoint failed", jsonBlob.fileName);
|
||||
else if (isLogging) console.log("success: ", jsonBlob.fileName);
|
||||
}
|
||||
|
||||
export function generateToken() {
|
||||
const url = "https://identity.dev.stratanetwork.net";
|
||||
const username = `perf1`;
|
||||
const password = "Password1";
|
||||
const dbguid = 'b8018250-af34-403e-bdcc-1770714042b2';
|
||||
|
||||
// token
|
||||
const tokenUrl = url + "/connect/token";
|
||||
const body = {
|
||||
database_guid: dbguid,
|
||||
grant_type: 'password',
|
||||
username: username,
|
||||
password: password,
|
||||
scope: 'strata.api.external offline_access',
|
||||
client_id: 'IntegrationTest',
|
||||
client_secret: 'UhAEQsGByTCrwPdHPLmaet_DmLEfcJVbZqGBxArdeRup_TPLrYKNpUNRHejjdnhd',
|
||||
};
|
||||
const params = {
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
}
|
||||
};
|
||||
const response = http.post(tokenUrl, body, params);
|
||||
if (response.status !== 200) {
|
||||
if (isLogging) console.log("error getting token: ", response);
|
||||
return false
|
||||
};
|
||||
const token = JSON.parse(response.body).access_token;
|
||||
if (isLogging) console.log("success getting token! access token: ", token);
|
||||
return token;
|
||||
}
|
||||
Reference in New Issue
Block a user