Skip to content

Instantly share code, notes, and snippets.

diff --git a/js/modules/k6/experimental/streams/clone-tests.sh b/js/modules/k6/experimental/streams/clone-tests.sh
new file mode 100755
index 000000000..aadbb483b
--- /dev/null
+++ b/js/modules/k6/experimental/streams/clone-tests.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+mkdir -p tests
+cd tests
@mstoykov
mstoykov / tracing-instrumentation.js
Last active April 9, 2024 13:48
k6/experimental/tracing in pure js
// This code specifically uses commonJS as to be faster loading in k6
// this can be changed after https://github.com/grafana/k6/issues/3265
const http = require("k6/http");
const crypto = require("k6/crypto");
const execution = require("k6/execution");
// saving the original values
const request = http.request;
const asyncRequest = http.asyncRequest;
@mstoykov
mstoykov / jsonMapToMapOfSharedArray.js
Created November 1, 2022 08:18
Small helper function making a json object into a map of sharedArrays - no checks that this will work are made
import { SharedArray } from "k6/data";
export function mapOfSharedArrays(file) {
let result = {};
let wholeFile;
let populateMap = () => {
if (wholeFile != null) { return; }
wholeFile = JSON.parse(open(file));
}
var keys = new SharedArray(file + "/keys", () => {
@mstoykov
mstoykov / async-transpiled.js
Created November 9, 2021 10:01
Transpilation of a async await with babel so it can be used in k6 (with WIP event loop
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
import { getter, sequentialIndex, randomizedUniqueIndex, uniquePerScenario, uniquePerVU } from "./lib.js";
import { SharedArray } from "k6/data";
// this are here for easier configuration
const vuNumbers = 3;
const dataPoints = 10;
function generateDataFor(number) {
var result = new Array(number)
for (let i=0;i<number;i++) {
? go.k6.io/k6 [no test files]
PASS
ok go.k6.io/k6/api 0.058s
? go.k6.io/k6/api/common [no test files]
PASS
ok go.k6.io/k6/api/v1 0.069s
? go.k6.io/k6/api/v1/client [no test files]
PASS
ok go.k6.io/k6/cloudapi 0.039s
PASS
@mstoykov
mstoykov / benchmarkShare.js
Last active March 2, 2021 08:23
SharedArray "benchmark"
import {check} from "k6";
import http from "k6/http";
import {SharedArray} from "k6/data"
var n = parseInt(__ENV.N)
function generateArray() {
var arr = new Array(n);
for (var i = 0; i< n; i++){
arr[i] = {"something": "something else" +i, "password": "12314561" }
}
@mstoykov
mstoykov / test.js
Last active January 14, 2021 13:40
Proof of concept arraybuffer to base64 and back in k6 based on https://gist.github.com/jonleighton/958841
function decodeArrayBuffer() {
console.log("------decodeEncodeFails()--------------");
const b64data = 'YAmMzu2PW2vfpUj22Dli4sk8I5muWlietj/gJR46gUIuWnswfaaT6XneRmP7oS34tUokHKAyL3jalq5cw7FFeA==';
var a = Base64Binary.decodeArrayBuffer(b64data)
console.log(a.byteLength);
console.log(a.length);
let enc = base64ArrayBuffer(a);
console.log("before = " + b64data);
console.log("after = " + enc);
@mstoykov
mstoykov / junit.xml
Created January 12, 2021 14:09
junit summary function
<?xml version="1.0"?>
<testsuites tests="2" failures="0">
<testsuite name="tresholds_junit.js" tests="2" failures="0">
<testcase name="http_req_duration + p(95)<50"><failure message="failed" ></testcase>
<testcase name="http_req_duration{url:http://httpbin.org/post} + max<1000" >
</testsuite>
</testsuites>
import http from "k6/http";
import { check } from "k6";
import aws from "https://gist.githubusercontent.com/MStoykov/38cc1293daa9080b11e26053589a6865/raw/9eee2c2f4af6d193d8e93719b6de2e09e451aa52/aws_k6.js";
function getSecret(region, keyname, params = {}) {
var body = `{"SecretId": "${keyname}"}`
var options = {};
options.method = "POST";
options.signSessionToken = true;
options.doubleEscape = false;