Skip to content

Commit

Permalink
fix: ensure all defined performance tests compile and run
Browse files Browse the repository at this point in the history
Signed-off-by: David Poltorak <[email protected]>
  • Loading branch information
davepoltorak committed Sep 27, 2023
1 parent 1a904a6 commit 168e817
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ConnectionService extends HttpService {
*/
getConnection(connectionId: string): Connection {
const res = this.get(`connections/${connectionId}`);
const connection = res.json() as unknown as Connection;
const connection = this.toJson(res) as unknown as Connection;
return connection;
}

Expand All @@ -36,7 +36,7 @@ export class ConnectionService extends HttpService {
*/
createConnection(): Connection {
const payload = { label: "test" };
const connection = this.post("connections", payload).json() as unknown as Connection;
const connection = this.toJson(this.post("connections", payload)) as unknown as Connection;
return connection;
}

Expand All @@ -48,7 +48,7 @@ export class ConnectionService extends HttpService {
acceptConnectionInvitation(invitation: ConnectionInvitation): Connection {
const payload = { invitation: this.invitationFromUrl(invitation.invitationUrl) };
const res = this.post("connection-invitations", payload, 200);
return res.json() as unknown as Connection;
return this.toJson(res) as unknown as Connection;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { sleep } from "k6";
import { HttpService } from "./HttpService";
import { ISSUER_AGENT_URL, WAITING_LOOP_MAX_ITERATIONS, WAITING_LOOP_PAUSE_INTERVAL } from "./Config";
import { IssueCredentialRecord, Connection, CredentialSchemaResponse } from "@input-output-hk/prism-typescript-client";
import {v4 as uuidv4} from 'uuid';
import { crypto } from "k6/experimental/webcrypto";


/**
* A service class for managing credentials in the application.
Expand All @@ -18,8 +19,8 @@ export class CredentialsService extends HttpService {
*/
createCredentialOffer(issuingDid: string, connection: Connection, schema: CredentialSchemaResponse): IssueCredentialRecord {
const payload = `{
"claims": {
"emailAddress": "${uuidv4()}[email protected]",
"claims": {
"emailAddress": "${crypto.randomUUID()}[email protected]",
"familyName": "Test",
"dateOfIssuance": "${new Date()}",
"drivingLicenseID": "Test",
Expand All @@ -31,13 +32,13 @@ export class CredentialsService extends HttpService {
"automaticIssuance": false
}`;
const res = this.post("issue-credentials/credential-offers", payload);
return res.json() as unknown as IssueCredentialRecord;
return this.toJson(res) as unknown as IssueCredentialRecord;
}

createCredentialSchema(issuingDid: string): CredentialSchemaResponse {
const payload = `
{
"name": "${uuidv4()}}",
"name": "${crypto.randomUUID()}}",
"version": "1.0.0",
"description": "Simple credential schema for the driving licence verifiable credential.",
"type": "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json",
Expand Down Expand Up @@ -85,7 +86,7 @@ export class CredentialsService extends HttpService {
}
`
const res = this.post("schema-registry/schemas", payload);
return res.json() as unknown as CredentialSchemaResponse;
return this.toJson(res) as unknown as CredentialSchemaResponse;
}

/**
Expand All @@ -95,7 +96,7 @@ export class CredentialsService extends HttpService {
*/
getCredentialRecord(record: IssueCredentialRecord): IssueCredentialRecord {
const res = this.get(`issue-credentials/records/${record.recordId}`);
return res.json() as unknown as IssueCredentialRecord;
return this.toJson(res) as unknown as IssueCredentialRecord;
}

/**
Expand All @@ -104,7 +105,7 @@ export class CredentialsService extends HttpService {
*/
getCredentialRecords(thid: string): IssueCredentialRecord[] {
const res = this.get(`issue-credentials/records?thid=${thid}`);
return res.json("contents") as unknown as IssueCredentialRecord[];
return this.toJson(res).contents as unknown as IssueCredentialRecord[];
}

/**
Expand All @@ -116,7 +117,7 @@ export class CredentialsService extends HttpService {
acceptCredentialOffer(record: IssueCredentialRecord, subjectDid: string): IssueCredentialRecord {
const payload = { subjectId: subjectDid };
const res = this.post(`issue-credentials/records/${record.recordId}/accept-offer`, payload, 200);
return res.json() as unknown as IssueCredentialRecord;
return this.toJson(res) as unknown as IssueCredentialRecord;
}

/**
Expand All @@ -126,7 +127,7 @@ export class CredentialsService extends HttpService {
*/
issueCredential(record: IssueCredentialRecord): IssueCredentialRecord {
const res = this.post(`issue-credentials/records/${record.recordId}/issue-credential`, null, 200);
return res.json() as unknown as IssueCredentialRecord;
return this.toJson(res) as unknown as IssueCredentialRecord;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { HttpService } from "./HttpService";
import { WAITING_LOOP_MAX_ITERATIONS, WAITING_LOOP_PAUSE_INTERVAL } from "./Config";
import { CreateManagedDIDResponse, DIDDocument, DidOperationSubmission, ManagedDID } from "@input-output-hk/prism-typescript-client";
import { sleep } from "k6";
import {check, sleep} from "k6";
import http from "k6/http";

/**
* A service class for managing decentralized identifiers (DIDs) in the application.
Expand All @@ -16,7 +17,7 @@ export class DidService extends HttpService {
*/
getDid(did: string): ManagedDID {
const res = this.get(`did-registrar/dids/${did}`);
return res.json() as unknown as ManagedDID;
return this.toJson(res) as unknown as ManagedDID;
}

/**
Expand All @@ -26,7 +27,7 @@ export class DidService extends HttpService {
*/
resolveDid(did: string): DIDDocument {
const res = this.get(`dids/${did}`);
return res.json() as unknown as DIDDocument;
return this.toJson(res) as unknown as DIDDocument;
}

/**
Expand All @@ -36,7 +37,7 @@ export class DidService extends HttpService {
*/
publishDid(did: string): DidOperationSubmission {
const res = this.post(`did-registrar/dids/${did}/publications`, null, 202);
return res.json("scheduledOperation") as unknown as DidOperationSubmission;
return this.toJson(res).scheduledOperation as unknown as DidOperationSubmission;
}

/**
Expand All @@ -46,7 +47,7 @@ export class DidService extends HttpService {
*/
createUnpublishedDid(documentTemplate: string): CreateManagedDIDResponse {
const res = this.post("did-registrar/dids", documentTemplate);
return res.json() as unknown as CreateManagedDIDResponse;
return this.toJson(res) as unknown as CreateManagedDIDResponse;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import http from 'k6/http';
import { check } from 'k6';
import {bytes, check} from 'k6';
import { RefinedResponse, ResponseType, RequestBody } from 'k6/http';

/**
Expand Down Expand Up @@ -34,6 +34,10 @@ export class HttpService {
};
}

public toJson(response: RefinedResponse<ResponseType>): any {
return JSON.parse(response.body as string)
}

/**
* Performs an HTTP POST request to the specified endpoint with the provided payload.
* @param endpoint The API endpoint to post to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ProofsService extends HttpService {
]
}`
const res = this.post("present-proof/presentations", payload);
return res.json("presentationId") as string;
return this.toJson(res).presentationId as string;
}

/**
Expand All @@ -51,7 +51,7 @@ export class ProofsService extends HttpService {
]
}`
const res = this.patch(`present-proof/presentations/${presentation.presentationId}`, payload);
return res.json("presentationId") as string;
return this.toJson(res).presentationId as string;
}

/**
Expand All @@ -61,7 +61,7 @@ export class ProofsService extends HttpService {
*/
getPresentation(presentationId: string): PresentationStatus {
const res = this.get(`present-proof/presentations/${presentationId}`);
return res.json() as unknown as PresentationStatus;
return this.toJson(res) as unknown as PresentationStatus;
}

/**
Expand All @@ -70,7 +70,7 @@ export class ProofsService extends HttpService {
*/
getPresentations(thid: string): PresentationStatus[] {
const res = this.get(`present-proof/presentations?thid=${thid}`);
return res.json("contents") as unknown as PresentationStatus[];
return this.toJson(res).contents as unknown as PresentationStatus[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Scenario, Threshold } from "k6/options";

export const defaultScenarios: { [name: string]: Scenario } = {
smoke: {
// a simple test to ensure performance tests work and requests don't fail
executor: "constant-vus",
vus: 3,
duration: "10s",
tags: { scenario_label: __ENV.SCENARIO_LABEL || "defaultScenarioLabel" }, // add label for filtering in observability platform
},
};

export const defaultThresholds: { [name: string]: Threshold[] } = {
http_req_failed: [
// fail if any requests fail during smoke test
{
threshold: "rate==0",
abortOnFail: true,
},
],
http_req_duration: [
// fail if any requests take longer than 500ms on smoke test
{ threshold: "p(95)<500", abortOnFail: true }, // 95% of requests should complete within 500ms
{ threshold: "p(99)<1500", abortOnFail: true }, // 99% of requests should complete within 1500ms
],
checks: ["rate==1"], // fail if any checks fail (the checks are defined in test code which is executed)
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,15 @@ import { group } from 'k6';
import { Options } from 'k6/options';
import { Issuer, Holder } from '../../actors';
import { Connection } from '@input-output-hk/prism-typescript-client';

// export let options: Options = {
// stages: [
// { duration: '1m', target: 5 },
// ],
// thresholds: {
// http_req_failed: [{
// threshold: 'rate<=0.05',
// abortOnFail: true,
// }],
// http_req_duration: ['p(95)<=100'],
// checks: ['rate>=0.99'],
// },
// };

import { defaultScenarios, defaultThresholds } from '../../scenarios/default';
export let options: Options = {
scenarios: {
smoke: {
executor: 'constant-vus',
vus: 3,
duration: "1s",
},
...defaultScenarios
},
thresholds: {
'http_req_duration{group:::Issuer creates credential offer}': ['max >= 0'],
'http_reqs{group:::Issuer creates credential offer}': ['count >= 0'],
'group_duration{group:::Issuer creates credential offer}': ['max >= 0'],
},
};

...defaultThresholds
}
}
export const issuer = new Issuer();
export const holder = new Holder();

Expand All @@ -52,7 +31,7 @@ export function setup() {
holder.finalizeConnectionWithIssuer();
});

return {
return {
issuerDid: issuer.did,
holderDid: holder.did,
connectionWithHolder: issuer.connectionWithHolder!,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
import { group } from 'k6';
import { Options } from 'k6/options';
import { Issuer } from '../../actors';

import { group } from "k6";
import { Options } from "k6/options";
import { Issuer } from "../../actors";
import {defaultScenarios, defaultThresholds} from "../../scenarios/default";
export let options: Options = {
scenarios: {
smoke: {
executor: 'constant-vus',
vus: 3,
duration: "1s",
},
...defaultScenarios
},
thresholds: {
'http_req_duration{group:::Issuer creates credential schema}': ['max >= 0'],
'http_reqs{group:::Issuer creates credential schema}': ['count >= 0'],
'group_duration{group:::Issuer creates credential schema}': ['max >= 0'],
checks: ['rate==1'],
http_req_duration: ['p(95)<=100'],
},
};

...defaultThresholds
}
}
export const issuer = new Issuer();

export function setup() {
group('Issuer publishes DID', function () {
group("Issuer publishes DID", function () {
issuer.createUnpublishedDid();
issuer.publishDid();
});

return {
return {
issuerDid: issuer.did,
};
}

export default (data: { issuerDid: string; }) => {

export default (data: { issuerDid: string }) => {
// This is the only way to pass data from setup to default
issuer.did = data.issuerDid;

group('Issuer creates credential schema', function () {
group("Issuer creates credential schema", function () {
issuer.createCredentialSchema();
});
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { Options } from 'k6/options';
import { Issuer } from '../../actors';

import {defaultScenarios, defaultThresholds} from "../../scenarios/default";
export let options: Options = {
scenarios: {
smoke: {
executor: 'constant-vus',
vus: 3,
duration: "1m",
scenarios: {
...defaultScenarios
},
},
thresholds: {
http_req_failed: [{
threshold: 'rate==0',
abortOnFail: true,
}],
http_req_duration: ['p(95)<=500'],
checks: ['rate==1'],
},
};
thresholds: {
...defaultThresholds
}
}

const issuer = new Issuer();

Expand Down
Loading

0 comments on commit 168e817

Please sign in to comment.