Skip to content

Commit

Permalink
add read to loadtest
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-block committed Oct 6, 2023
1 parent a5c2ab2 commit bf45f2e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
66 changes: 42 additions & 24 deletions loadtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ if (!globalThis.crypto) {
}

import type { Signer } from '@tbd54566975/dwn-sdk-js';
import { DidKeyResolver, Jws, RecordsWrite } from '@tbd54566975/dwn-sdk-js';
import {
DidKeyResolver,
Jws,
RecordsWrite,
RecordsRead,
} from '@tbd54566975/dwn-sdk-js';

const DWN_SERVER = 'http://localhost:3000';

class response {
status: number;
time: number;

constructor(status: number, time: number) {
this.status = status;
this.time = time;
}
}
const responses: response[] = [];
let running = true;
Expand Down Expand Up @@ -70,28 +80,6 @@ async function doAll(iterations: number, vuCount: number): Promise<void> {
}
}

async function rpcRequest(method: string, params): Promise<void> {
const req = {
jsonrpc: '2.0',
id: randomUUID(),
method: method,
params: params,
};

const start = Date.now();
const resp = await fetch(DWN_SERVER, {
method: 'POST',
headers: { 'dwn-request': JSON.stringify(req) },
});

const time = Date.now() - start;

responses.push({
status: resp.status,
time: time,
});
}

async function doTest(
iterations: number,
did: string,
Expand All @@ -114,9 +102,39 @@ async function doTest(
target: did,
message: recordsWriteMessage,
});

const { message: recordsReadMessage } = await RecordsRead.create({
filter: {
recordId: recordsWriteMessage.recordId,
},
authorizationSigner,
});
await rpcRequest('dwn.processMessage', {
target: did,
message: recordsReadMessage,
});
}
}

async function rpcRequest(method: string, params: any): Promise<void> {
const req = {
jsonrpc: '2.0',
id: randomUUID(),
method: method,
params: params,
};

const start = Date.now();
const resp = await fetch(DWN_SERVER, {
method: 'POST',
headers: { 'dwn-request': JSON.stringify(req) },
});

const time = Date.now() - start;

responses.push(new response(resp.status, time));
}

async function writeProgress(): Promise<void> {
const start = Date.now();
while (running) {
Expand All @@ -132,4 +150,4 @@ async function writeProgress(): Promise<void> {
process.stdout.write('\n');
}

doAll(100, 100);
doAll(100, 10);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"test": "npm run build:esm && cp -R tests/fixtures dist/esm/tests && c8 mocha",
"server": "npm run build:esm && node dist/esm/src/main.js",
"prepare": "husky install",
"loadtest": "tsc --moduleResolution nodenext --module nodenext loadtest.ts && node loadtest.js"
"loadtest": "tsc --moduleResolution nodenext --module nodenext --strict loadtest.ts && node loadtest.js"
},
"husky": {
"hooks": {
Expand Down

0 comments on commit bf45f2e

Please sign in to comment.