From 33456c8437b43b7e96b32dd7868ad2a5955f733e Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Wed, 12 Mar 2025 22:24:16 -0400 Subject: [PATCH] [ci skip] progress on performance logging in tests --- veilid-wasm/tests/.gitignore | 3 +- .../tests/src/VeilidRoutingContext.test.ts | 23 +++--- veilid-wasm/tests/src/services/FileService.ts | 78 +++++++++++++++++++ veilid-wasm/tests/test_results/.gitkeep | 0 veilid-wasm/tests/wdio.conf.ts | 10 +-- 5 files changed, 95 insertions(+), 19 deletions(-) create mode 100644 veilid-wasm/tests/src/services/FileService.ts create mode 100644 veilid-wasm/tests/test_results/.gitkeep diff --git a/veilid-wasm/tests/.gitignore b/veilid-wasm/tests/.gitignore index 3091757a..7f5114b9 100644 --- a/veilid-wasm/tests/.gitignore +++ b/veilid-wasm/tests/.gitignore @@ -1,2 +1,3 @@ node_modules -coverage \ No newline at end of file +coverage +test_results \ No newline at end of file diff --git a/veilid-wasm/tests/src/VeilidRoutingContext.test.ts b/veilid-wasm/tests/src/VeilidRoutingContext.test.ts index 80028ebf..58a3f3ce 100644 --- a/veilid-wasm/tests/src/VeilidRoutingContext.test.ts +++ b/veilid-wasm/tests/src/VeilidRoutingContext.test.ts @@ -1,6 +1,4 @@ import { expect } from '@wdio/globals'; -import * as fs from 'fs'; -import * as path from 'path'; import { veilidCoreInitConfig, @@ -114,15 +112,14 @@ describe('VeilidRoutingContext', () => { describe('DHT stress tests', () => { before(async () => { - await browser.cdp("Profiler", "enable") - await browser.cdp("Profiler", "start") + await browser.startTracing({}) }) it('should inspect in parallel without delay', async () => { - const recordCount = 16; - const subkeyCount = 32; - const inspectCount = 10; + const recordCount = 2; + const subkeyCount = 4; + const inspectCount = 4; const data = textEncoder.encode('🚀 This example DHT data with unicode a Ā 𐀀 文 🚀'); let a = Array(); @@ -146,7 +143,7 @@ describe('VeilidRoutingContext', () => { data, ); - console.log(performance.measure(measureName, measureName + "-start").toJSON()) + performance.measure(measureName, measureName + "-start") })()); } @@ -162,7 +159,7 @@ describe('VeilidRoutingContext', () => { "SyncSet", ); - console.log(performance.measure(measureName, measureName + "-start").toJSON()) + performance.measure(measureName, measureName + "-start") })()); } } @@ -173,11 +170,11 @@ describe('VeilidRoutingContext', () => { after(async () => { - let profile = await browser.cdp("Profiler", "stop") + const events = await browser.endTracing() + if (events) { + await browser.writeFile("profile-dht-stress-test.json", events); + } - fs.writeFileSync(path.join(__dirname, "profile.json"), JSON.stringify(profile)); - - await browser.cdp("Profiler", "disable") }) }); diff --git a/veilid-wasm/tests/src/services/FileService.ts b/veilid-wasm/tests/src/services/FileService.ts new file mode 100644 index 00000000..17d373d1 --- /dev/null +++ b/veilid-wasm/tests/src/services/FileService.ts @@ -0,0 +1,78 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import type { Services } from '@wdio/types'; +import { fileURLToPath } from 'node:url'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +declare global { + namespace WebdriverIO { + interface Browser { + /** + * Write data to a file + * @param filename The path to the file to write + * @param data The data to write to the file (string, Buffer, or object) + * @returns Promise that resolves when the file has been written + */ + writeFile(filename: string, data: string | Buffer | object): Promise; + } + } +} + +export class FileService implements Services.ServiceInstance { + /** + * Constructor for the FileService + * @param _options Service options (unused) + * @param _capabilities WebdriverIO capabilities (unused) + * @param _config WebdriverIO config (unused) + */ + constructor( + private _options: Record = {}, + private _capabilities: WebdriverIO.Capabilities = {}, + private _config: WebdriverIO.Config = { capabilities: [{}] } + ) { } + + /** + * Before hook that gets executed before test execution begins + * This is where we add our custom commands to the browser object + */ + before( + _capabilities: WebdriverIO.Capabilities, + _specs: string[], + browser: WebdriverIO.Browser + ): void { + /** + * Add a writeFile command to the browser object + * @param filename The path to the file to write + * @param data The data to write to the file + * @returns Promise that resolves when the file has been written + */ + browser.addCommand('writeFile', async function ( + filename: string, + data: string | Buffer | object + ): Promise { + const fullPath = path.resolve(__dirname, '../../', filename); + // Ensure the directory exists + const dirname = path.dirname(fullPath); + if (!fs.existsSync(dirname)) { + fs.mkdirSync(dirname, { recursive: true }); + } + + // If data is an object, stringify it + const content = typeof data === 'object' && !(data instanceof Buffer) + ? JSON.stringify(data, null, 2) + : data; + + // Write the file + return new Promise((resolve, reject) => { + fs.writeFile(filename, content, (err: NodeJS.ErrnoException | null) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + }); + } +} \ No newline at end of file diff --git a/veilid-wasm/tests/test_results/.gitkeep b/veilid-wasm/tests/test_results/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/veilid-wasm/tests/wdio.conf.ts b/veilid-wasm/tests/wdio.conf.ts index 6294111b..2926dda6 100644 --- a/veilid-wasm/tests/wdio.conf.ts +++ b/veilid-wasm/tests/wdio.conf.ts @@ -1,6 +1,8 @@ /// /// +import { FileService } from './src/services/FileService'; + export const config: WebdriverIO.Config = { // // ==================== @@ -101,10 +103,8 @@ export const config: WebdriverIO.Config = { // - @wdio/sumologic-reporter // - @wdio/cli, @wdio/config, @wdio/utils // Level of logging verbosity: trace | debug | info | warn | error | silent - // logLevels: { - // webdriver: 'info', - // '@wdio/appium-service': 'info' - // }, + logLevels: { + }, // // If you only want to run your tests until a specific amount of tests have failed use // bail (default is 0 - don't bail, run all tests). @@ -130,7 +130,7 @@ export const config: WebdriverIO.Config = { // Services take over a specific job you don't want to take care of. They enhance // your test setup with almost no effort. Unlike plugins, they don't add new // commands. Instead, they hook themselves up into the test process. - services: ['devtools'], + services: ['devtools', [FileService as any, {}]], // // Framework you want to run your specs with. // The following are supported: Mocha, Jasmine, and Cucumber