Better logging for hanging benchmarks
This commit is contained in:
parent
adf2957537
commit
51c2029b5c
9 changed files with 446 additions and 458 deletions
|
@ -5,103 +5,87 @@
|
|||
import assert from 'assert';
|
||||
import type { PrimaryDevice } from '@signalapp/mock-server';
|
||||
|
||||
import type { App } from './fixtures';
|
||||
import { Bootstrap, debug, stats, RUN_COUNT, DISCARD_COUNT } from './fixtures';
|
||||
|
||||
const CONVERSATION_SIZE = 1000; // messages
|
||||
const DELAY = 50; // milliseconds
|
||||
|
||||
void (async () => {
|
||||
const bootstrap = new Bootstrap({
|
||||
benchmark: true,
|
||||
});
|
||||
Bootstrap.benchmark(async (bootstrap: Bootstrap): Promise<void> => {
|
||||
const app = await bootstrap.link();
|
||||
const { server, contacts, phone, desktop } = bootstrap;
|
||||
|
||||
await bootstrap.init();
|
||||
const [first, second] = contacts;
|
||||
|
||||
let app: App | undefined;
|
||||
try {
|
||||
app = await bootstrap.link();
|
||||
const { server, contacts, phone, desktop } = bootstrap;
|
||||
const messages = new Array<Buffer>();
|
||||
debug('encrypting');
|
||||
// Send messages from just two contacts
|
||||
for (const contact of [second, first]) {
|
||||
for (let i = 0; i < CONVERSATION_SIZE; i += 1) {
|
||||
const messageTimestamp = bootstrap.getTimestamp();
|
||||
messages.push(
|
||||
await contact.encryptText(
|
||||
desktop,
|
||||
`hello from: ${contact.profileName}`,
|
||||
{
|
||||
timestamp: messageTimestamp,
|
||||
sealed: true,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
const [first, second] = contacts;
|
||||
|
||||
const messages = new Array<Buffer>();
|
||||
debug('encrypting');
|
||||
// Send messages from just two contacts
|
||||
for (const contact of [second, first]) {
|
||||
for (let i = 0; i < CONVERSATION_SIZE; i += 1) {
|
||||
const messageTimestamp = bootstrap.getTimestamp();
|
||||
messages.push(
|
||||
await contact.encryptText(
|
||||
desktop,
|
||||
`hello from: ${contact.profileName}`,
|
||||
messages.push(
|
||||
await phone.encryptSyncRead(desktop, {
|
||||
timestamp: bootstrap.getTimestamp(),
|
||||
messages: [
|
||||
{
|
||||
senderUUID: contact.device.uuid,
|
||||
timestamp: messageTimestamp,
|
||||
sealed: true,
|
||||
}
|
||||
)
|
||||
);
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
messages.push(
|
||||
await phone.encryptSyncRead(desktop, {
|
||||
timestamp: bootstrap.getTimestamp(),
|
||||
messages: [
|
||||
{
|
||||
senderUUID: contact.device.uuid,
|
||||
timestamp: messageTimestamp,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
const sendQueue = async (): Promise<void> => {
|
||||
await Promise.all(messages.map(message => server.send(desktop, message)));
|
||||
};
|
||||
|
||||
const measure = async (): Promise<void> => {
|
||||
assert(app);
|
||||
const window = await app.getWindow();
|
||||
|
||||
const leftPane = window.locator('.left-pane-wrapper');
|
||||
|
||||
const openConvo = async (contact: PrimaryDevice): Promise<void> => {
|
||||
debug('opening conversation', contact.profileName);
|
||||
const item = leftPane.locator(
|
||||
`[data-testid="${contact.toContact().uuid}"]`
|
||||
);
|
||||
|
||||
await item.click();
|
||||
};
|
||||
|
||||
const deltaList = new Array<number>();
|
||||
for (let runId = 0; runId < RUN_COUNT + DISCARD_COUNT; runId += 1) {
|
||||
await openConvo(runId % 2 === 0 ? first : second);
|
||||
|
||||
debug('waiting for timing from the app');
|
||||
const { delta } = await app.waitForConversationOpen();
|
||||
|
||||
// Let render complete
|
||||
await new Promise(resolve => setTimeout(resolve, DELAY));
|
||||
|
||||
if (runId >= DISCARD_COUNT) {
|
||||
deltaList.push(delta);
|
||||
console.log('run=%d info=%j', runId - DISCARD_COUNT, { delta });
|
||||
} else {
|
||||
console.log('discarded=%d info=%j', runId, { delta });
|
||||
}
|
||||
}
|
||||
|
||||
const sendQueue = async (): Promise<void> => {
|
||||
await Promise.all(messages.map(message => server.send(desktop, message)));
|
||||
};
|
||||
console.log('stats info=%j', { delta: stats(deltaList, [99, 99.8]) });
|
||||
};
|
||||
|
||||
const measure = async (): Promise<void> => {
|
||||
assert(app);
|
||||
const window = await app.getWindow();
|
||||
|
||||
const leftPane = window.locator('.left-pane-wrapper');
|
||||
|
||||
const openConvo = async (contact: PrimaryDevice): Promise<void> => {
|
||||
debug('opening conversation', contact.profileName);
|
||||
const item = leftPane.locator(
|
||||
`[data-testid="${contact.toContact().uuid}"]`
|
||||
);
|
||||
|
||||
await item.click();
|
||||
};
|
||||
|
||||
const deltaList = new Array<number>();
|
||||
for (let runId = 0; runId < RUN_COUNT + DISCARD_COUNT; runId += 1) {
|
||||
await openConvo(runId % 2 === 0 ? first : second);
|
||||
|
||||
debug('waiting for timing from the app');
|
||||
const { delta } = await app.waitForConversationOpen();
|
||||
|
||||
// Let render complete
|
||||
await new Promise(resolve => setTimeout(resolve, DELAY));
|
||||
|
||||
if (runId >= DISCARD_COUNT) {
|
||||
deltaList.push(delta);
|
||||
console.log('run=%d info=%j', runId - DISCARD_COUNT, { delta });
|
||||
} else {
|
||||
console.log('discarded=%d info=%j', runId, { delta });
|
||||
}
|
||||
}
|
||||
|
||||
console.log('stats info=%j', { delta: stats(deltaList, [99, 99.8]) });
|
||||
};
|
||||
|
||||
await Promise.all([sendQueue(), measure()]);
|
||||
} catch (error) {
|
||||
await bootstrap.saveLogs(app);
|
||||
throw error;
|
||||
} finally {
|
||||
await app?.close();
|
||||
await bootstrap.teardown();
|
||||
}
|
||||
})();
|
||||
await Promise.all([sendQueue(), measure()]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue