From b1d89bda6c7952b7d60f560894aadc1544cc53ce Mon Sep 17 00:00:00 2001 From: chad Date: Wed, 26 Jul 2023 14:16:25 -0500 Subject: [PATCH] feat: added perf test and output to JSON --- packages/perf/src/index.ts | 2 +- packages/perf/src/main.ts | 68 ++++++++++++++++---------------- packages/perf/test/index.spec.ts | 2 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/perf/src/index.ts b/packages/perf/src/index.ts index 4ac0a86c77..8ed9261a86 100644 --- a/packages/perf/src/index.ts +++ b/packages/perf/src/index.ts @@ -143,7 +143,7 @@ export class DefaultPerfService implements Startable, PerfService { } log('performed %s to %p', this.protocol, peer) - stream.close() + await stream.close() } // measureDownloadBandwidth returns the measured bandwidth in bits per second diff --git a/packages/perf/src/main.ts b/packages/perf/src/main.ts index b7c93ca992..4aa3b2a378 100644 --- a/packages/perf/src/main.ts +++ b/packages/perf/src/main.ts @@ -25,41 +25,41 @@ export const defaultInit: PerfServiceInit = { const argv = yargs .options({ - 'run-server': { - type: 'boolean', - demandOption: true, - default: false, - description: 'Whether to run as a server', - }, - 'server-ip-address': { - type: 'string', - demandOption: false, - description: 'Server IP address', - default: '', - }, - 'transport': { - type: 'string', - demandOption: false, - description: 'Transport to use', - default: 'tcp' - }, - 'upload-bytes': { - type: 'number', - demandOption: false, - description: 'Number of bytes to upload', - default: 0 - }, - 'download-bytes': { - type: 'number', - demandOption: false, - description: 'Number of bytes to download', - default: 0 - }, + 'run-server': { + type: 'boolean', + demandOption: true, + default: false, + description: 'Whether to run as a server', + }, + 'server-ip-address': { + type: 'string', + demandOption: false, + description: 'Server IP address', + default: '', + }, + 'transport': { + type: 'string', + demandOption: false, + description: 'Transport to use', + default: 'tcp' + }, + 'upload-bytes': { + type: 'number', + demandOption: false, + description: 'Number of bytes to upload', + default: 0 + }, + 'download-bytes': { + type: 'number', + demandOption: false, + description: 'Number of bytes to download', + default: 0 + }, }) .command('help', 'Print usage information', yargs.help) .parseSync() -export async function main(runServer: boolean, serverIpAddress: string, transport: string, uploadBytes: number, downloadBytes: number): void { +export async function main(runServer: boolean, serverIpAddress: string, transport: string, uploadBytes: number, downloadBytes: number): Promise { const listenAddrs: Multiaddr[] = [] if (runServer === true) { @@ -72,10 +72,10 @@ export async function main(runServer: boolean, serverIpAddress: string, transpor const remoteComponents = await createComponents() const client = perfService(defaultInit)(localComponents) - const server = perfService(defaultInit)(remoteComponents) + const server = perfService(defaultInit)(remoteComponents) - await start(client) - await start(server) + await start(client) + await start(server) const startTime = Date.now() diff --git a/packages/perf/test/index.spec.ts b/packages/perf/test/index.spec.ts index cd0d333475..e0ee3a22fd 100644 --- a/packages/perf/test/index.spec.ts +++ b/packages/perf/test/index.spec.ts @@ -3,7 +3,7 @@ import { start, stop } from '@libp2p/interface/startable' import { connectionPair } from '@libp2p/interface-compliance-tests/mocks' import { expect } from 'aegir/chai' -import { type Components } from 'libp2p/components' +import type { Components } from 'libp2p/components' import { perfService } from '../src/index.js' import { createComponents, defaultInit } from '../src/main.js'