Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 K6 create issuers #918

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/k6/.mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
node = "20"
21 changes: 21 additions & 0 deletions scripts/k6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,24 @@
```
cp env.local .env.local
```

### Running Biome to lint/format code:

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 1; Actual: 0; Below Warning

Expected: 1; Actual: 0; Below

Check warning

Code scanning / Markdownlint (reported by Codacy)

Punctuation: ':' Warning

Punctuation: ':'
```

Check warning

Code scanning / Markdownlint (reported by Codacy)

Fenced code blocks should have a language specified Warning

Fenced code blocks should have a language specified

Check warning

Code scanning / Markdownlint (reported by Codacy)

Fenced code blocks should be surrounded by blank lines Warning

Fenced code blocks should be surrounded by blank lines
# Use mise to install Node
mise install

# Use npm to install Biome - `ci` for frozen lockfile
npm ci

# check formatting but don't actually write anything
npm run format:check

# format code
npm run format

# check linting but don't try to auto-fix
npm run lint

# lint and auto-fix if possible
npm run lint:fix
```
16 changes: 16 additions & 0 deletions scripts/k6/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignore": ["node_modules", "output"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
},
"ignore": ["node_modules", "output"]
}
}
8 changes: 4 additions & 4 deletions scripts/k6/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ fi

export K6_STATSD_ENABLE_TAGS=true
export SKIP_DELETE_ISSUERS=true
export VUS=1
export ITERATIONS=5
export ISSUER_PREFIX=k6_issuer_dev2
export HOLDER_PREFIX=k6_holder_dev_a
export VUS=5
export ITERATIONS=2
export ISSUER_PREFIX=k6_issuer
export HOLDER_PREFIX=k6_holder
export SCHEMA_NAME="proof_of_person"
export SCHEMA_VERSION="0.1.0"
167 changes: 167 additions & 0 deletions scripts/k6/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/k6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": {
"format:check": "biome format .",
"format": "biome format --write .",
"lint:fix": "biome lint --write --unsafe .",
"lint": "biome lint ."
},
"devDependencies": {
"@biomejs/biome": "^1.8.3"
}
}
8 changes: 6 additions & 2 deletions scripts/k6/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ run_test() {
run_test true true ./scenarios/create-holders.js
run_test true true ./scenarios/create-invitation.js
run_test true true ./scenarios/create-credentials.js
run_test true true ./scenarios/create-proof.js
run_test false false ./scenarios/delete-holders.js
run_test false true ./scenarios/create-proof.js
run_test true false ./scenarios/delete-holders.js

run_test false true ./scenarios/create-issuers.js

echo "All tests completed successfully"

# TODO: Better logic to handle deleting issuers and holders
130 changes: 130 additions & 0 deletions scripts/k6/scenarios/create-issuers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* global __ENV, __ITER, __VU */
// Solve Codacy '__ENV' is not defined. error

import { check } from 'k6';

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
import { SharedArray } from 'k6/data';

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
import { getBearerToken } from '../libs/auth.js';

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
import { Trend, Counter } from 'k6/metrics';

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
import {
getWalletIdByWalletName,
deleteTenant,
createIssuerTenant,
getTrustRegistryActor,
createCredentialDefinition,
} from '../libs/functions.js';

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.

const vus = parseInt(__ENV.VUS, 10);
const iterations = parseInt(__ENV.ITERATIONS, 10);
const issuerPrefix = __ENV.ISSUER_PREFIX;
// const holderPrefix = __ENV.HOLDER_PREFIX;

export let options = {
scenarios: {
default: {
executor: 'per-vu-iterations',

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
vus: vus,

Check notice

Code scanning / Eslint (reported by Codacy)

Expected property shorthand. Note

Expected property shorthand.
iterations: iterations,

Check notice

Code scanning / Eslint (reported by Codacy)

Expected property shorthand. Note

Expected property shorthand.
maxDuration: '24h',

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
},
},
setupTimeout: '300s', // Increase the setup timeout to 120 seconds

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
teardownTimeout: '120s', // Increase the teardown timeout to 120 seconds

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
maxRedirects: 4,
thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2
'http_req_duration{scenario:default}': [`max>=0`],

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
'http_reqs{scenario:default}': ['count >= 0'],

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
'iteration_duration{scenario:default}': ['max>=0'],

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
},
tags: {
test_run_id: 'phased-issuance',

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.

Check warning

Code scanning / Eslint (reported by Codacy)

Identifier 'test_run_id' is not in camel case. Warning

Identifier 'test_run_id' is not in camel case.
test_phase: 'create-issuers',

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.

Check warning

Code scanning / Eslint (reported by Codacy)

Identifier 'test_phase' is not in camel case. Warning

Identifier 'test_phase' is not in camel case.
},
};

const testFunctionReqs = new Counter('test_function_reqs');

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
const mainIterationDuration = new Trend('main_iteration_duration');

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.

// Seed data: Generating a list of options.iterations unique wallet names
const wallets = new SharedArray('wallets', function() {

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
const walletsArray = [];
for (let i = 0; i < options.scenarios.default.iterations * options.scenarios.default.vus; i++) {
walletsArray.push({
walletLabel: `${issuerPrefix} ${i}`,
walletName: `${issuerPrefix}_${i}`
});
}
return walletsArray;
});

export function setup() {
const bearerToken = getBearerToken();
return { bearerToken };

Check warning

Code scanning / Pmd (reported by Codacy)

Unnecessary block. Warning

Unnecessary block.
}

const iterationsPerVU = options.scenarios.default.iterations;
// Helper function to calculate the wallet index based on VU and iteration
function getWalletIndex(vu, iter) {
const walletIndex = (vu - 1) * iterationsPerVU + (iter - 1);
return walletIndex;
}

export default function(data) {
const start = Date.now();
const bearerToken = data.bearerToken;
const walletIndex = getWalletIndex(__VU, __ITER + 1); // __ITER starts from 0, adding 1 to align with the logic
const wallet = wallets[walletIndex];
const credDefTag = wallet.walletName;

const createIssuerTenantResponse = createIssuerTenant(bearerToken, wallet.walletName);
check(createIssuerTenantResponse, {
"Issuer tenant created successfully": (r) => r.status === 200
});
const issuerAccessToken = createIssuerTenantResponse.json().access_token;

const getTrustRegistryActorResponse = getTrustRegistryActor(wallet.walletName);
check(getTrustRegistryActorResponse, {
"Trust Registry Actor Response status code is 200": (r) => {
if (r.status !== 200) {
console.error(`Unexpected response status while getting trust registry actor for issuer tenant ${wallet.walletName}: ${r.status}`);

Check warning

Code scanning / Eslint (reported by Codacy)

Unexpected console statement. Warning

Unexpected console statement.
return false;
} else {
console.log(`Got trust registry actor for issuer tenant ${wallet.walletName} successfully.`);

Check warning

Code scanning / Eslint (reported by Codacy)

Unexpected console statement. Warning

Unexpected console statement.
return true;
}
}
});

// const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag);
// check(createCredentialDefinitionResponse, {
// "Credential definition created successfully": (r) => r.status === 200
// });

const end = Date.now();
const duration = end - start;
// console.log(`Duration for iteration ${__ITER}: ${duration} ms`);
mainIterationDuration.add(duration);
testFunctionReqs.add(1);
}

export function teardown(data) {
const bearerToken = data.bearerToken;

// // Delete issuer tenants
if (__ENV.SKIP_DELETE_ISSUERS !== 'true') {

Check warning

Code scanning / Eslint (reported by Codacy)

Strings must use doublequote. Warning

Strings must use doublequote.
for (const wallet of wallets) {
const walletId = getWalletIdByWalletName(bearerToken, wallet.walletName);
const deleteIssuerResponse = deleteTenant(bearerToken, walletId);
check (deleteIssuerResponse, {
"Delete Issuer Tenant Response status code is 200": (r) => {
if (r.status !== 200) {
console.error(`Unexpected response status while deleting issuer tenant ${walletId}: ${r.status}`);

Check warning

Code scanning / Eslint (reported by Codacy)

Unexpected console statement. Warning

Unexpected console statement.
return false;
} else {
console.log(`Deleted issuer tenant ${walletId} successfully.`);

Check warning

Code scanning / Eslint (reported by Codacy)

Unexpected console statement. Warning

Unexpected console statement.
return true;
}
}
});
}
}
}
Loading