[ci skip] progress on performance logging in tests

This commit is contained in:
Christien Rioux 2025-03-12 22:24:16 -04:00
parent 27a102bf7c
commit 33456c8437
5 changed files with 95 additions and 19 deletions

View File

@ -1,2 +1,3 @@
node_modules
coverage
test_results

View File

@ -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")
})
});

View File

@ -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<void>;
}
}
}
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<string, any> = {},
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<void> {
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<void>((resolve, reject) => {
fs.writeFile(filename, content, (err: NodeJS.ErrnoException | null) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
});
}
}

View File

View File

@ -1,6 +1,8 @@
/// <reference types="node" />
/// <reference types="@wdio/types" />
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