From bf45f2eb5afe3aad609a5ab66dbfc65b175c9d96 Mon Sep 17 00:00:00 2001 From: finn Date: Wed, 4 Oct 2023 11:45:33 -0700 Subject: [PATCH] add read to loadtest --- loadtest.ts | 66 +++++++++++++++++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/loadtest.ts b/loadtest.ts index 0b6aa98..413f278 100644 --- a/loadtest.ts +++ b/loadtest.ts @@ -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; @@ -70,28 +80,6 @@ async function doAll(iterations: number, vuCount: number): Promise { } } -async function rpcRequest(method: string, params): Promise { - 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, @@ -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 { + 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 { const start = Date.now(); while (running) { @@ -132,4 +150,4 @@ async function writeProgress(): Promise { process.stdout.write('\n'); } -doAll(100, 100); +doAll(100, 10); diff --git a/package.json b/package.json index 019a335..bf3ffdd 100644 --- a/package.json +++ b/package.json @@ -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": {