2022-02-11 22:32:51 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
/* eslint-disable no-await-in-loop, no-console */
|
|
|
|
|
2022-07-08 20:46:25 +00:00
|
|
|
import assert from 'assert';
|
2022-02-11 22:32:51 +00:00
|
|
|
import type { PrimaryDevice } from '@signalapp/mock-server';
|
|
|
|
|
2023-07-20 22:37:56 +00:00
|
|
|
import { Bootstrap, debug, RUN_COUNT, DISCARD_COUNT } from './fixtures';
|
|
|
|
import { stats } from '../../util/benchmark/stats';
|
2023-12-19 20:03:01 +00:00
|
|
|
import { sleep } from '../../util/sleep';
|
2022-02-11 22:32:51 +00:00
|
|
|
|
|
|
|
const CONVERSATION_SIZE = 1000; // messages
|
|
|
|
const DELAY = 50; // milliseconds
|
2023-12-19 20:03:01 +00:00
|
|
|
const WAIT_FOR_MESSAGES_TO_BE_PROCESSED = 5000; // milliseconds
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
Bootstrap.benchmark(async (bootstrap: Bootstrap): Promise<void> => {
|
|
|
|
const app = await bootstrap.link();
|
|
|
|
const { server, contacts, phone, desktop } = bootstrap;
|
|
|
|
|
|
|
|
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}`,
|
|
|
|
{
|
|
|
|
timestamp: messageTimestamp,
|
|
|
|
sealed: true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
messages.push(
|
|
|
|
await phone.encryptSyncRead(desktop, {
|
|
|
|
timestamp: bootstrap.getTimestamp(),
|
|
|
|
messages: [
|
2022-02-11 22:32:51 +00:00
|
|
|
{
|
2023-08-16 20:54:39 +00:00
|
|
|
senderAci: contact.device.aci,
|
2022-02-11 22:32:51 +00:00
|
|
|
timestamp: messageTimestamp,
|
2023-03-13 23:41:47 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
);
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
2023-03-13 23:41:47 +00:00
|
|
|
}
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const sendQueue = async (): Promise<void> => {
|
|
|
|
await Promise.all(messages.map(message => server.send(desktop, message)));
|
|
|
|
};
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const measure = async (): Promise<void> => {
|
|
|
|
assert(app);
|
|
|
|
const window = await app.getWindow();
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const leftPane = window.locator('#LeftPane');
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const openConvo = async (contact: PrimaryDevice): Promise<void> => {
|
|
|
|
debug('opening conversation', contact.profileName);
|
|
|
|
const item = leftPane.locator(
|
2023-08-16 20:54:39 +00:00
|
|
|
`[data-testid="${contact.toContact().aci}"]`
|
2023-03-13 23:41:47 +00:00
|
|
|
);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
await item.click();
|
|
|
|
};
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const deltaList = new Array<number>();
|
|
|
|
for (let runId = 0; runId < RUN_COUNT + DISCARD_COUNT; runId += 1) {
|
|
|
|
await openConvo(runId % 2 === 0 ? first : second);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
debug('waiting for timing from the app');
|
|
|
|
const { delta } = await app.waitForConversationOpen();
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
// Let render complete
|
|
|
|
await new Promise(resolve => setTimeout(resolve, DELAY));
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
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 });
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
2023-03-13 23:41:47 +00:00
|
|
|
}
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
console.log('stats info=%j', { delta: stats(deltaList, [99, 99.8]) });
|
|
|
|
};
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-12-19 20:03:01 +00:00
|
|
|
await sendQueue();
|
|
|
|
await sleep(WAIT_FOR_MESSAGES_TO_BE_PROCESSED);
|
|
|
|
await measure();
|
2023-03-13 23:41:47 +00:00
|
|
|
});
|