2022-03-09 18:22:34 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
/* eslint-disable no-await-in-loop, no-console */
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
import type { PrimaryDevice } from '@signalapp/mock-server';
|
2022-03-09 18:22:34 +00:00
|
|
|
import { StorageState } from '@signalapp/mock-server';
|
|
|
|
|
2022-07-08 20:46:25 +00:00
|
|
|
import type { App } from './fixtures';
|
|
|
|
import { Bootstrap } from './fixtures';
|
2022-03-09 18:22:34 +00:00
|
|
|
|
|
|
|
const CONTACT_COUNT = 1000;
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void (async () => {
|
2022-03-09 18:22:34 +00:00
|
|
|
const contactNames = new Array<string>();
|
|
|
|
for (let i = 0; i < CONTACT_COUNT; i += 1) {
|
|
|
|
contactNames.push(`Contact ${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bootstrap = new Bootstrap({
|
|
|
|
benchmark: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
await bootstrap.init();
|
|
|
|
const { phone, server } = bootstrap;
|
|
|
|
|
|
|
|
let state = StorageState.getEmpty();
|
2023-01-13 00:24:59 +00:00
|
|
|
let lastContact: PrimaryDevice | undefined;
|
2022-03-09 18:22:34 +00:00
|
|
|
for (const [i, profileName] of contactNames.entries()) {
|
|
|
|
const contact = await server.createPrimaryDevice({
|
|
|
|
profileName,
|
|
|
|
});
|
|
|
|
|
|
|
|
state = state.addContact(contact, {
|
|
|
|
// Make sure we fetch profile from the server
|
|
|
|
givenName: `Loading ${profileName}...`,
|
|
|
|
|
|
|
|
identityKey: contact.publicKey.serialize(),
|
|
|
|
profileKey: contact.profileKey.serialize(),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (i >= contactNames.length - 4) {
|
|
|
|
state = state.pin(contact);
|
|
|
|
}
|
2023-01-13 00:24:59 +00:00
|
|
|
|
|
|
|
if (i === contactNames.length - 1) {
|
|
|
|
lastContact = contact;
|
|
|
|
}
|
2022-03-09 18:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await phone.setStorageState(state);
|
|
|
|
|
|
|
|
const start = Date.now();
|
2022-07-08 20:46:25 +00:00
|
|
|
let app: App | undefined;
|
2022-03-09 18:22:34 +00:00
|
|
|
try {
|
2022-07-08 20:46:25 +00:00
|
|
|
app = await bootstrap.link();
|
2022-03-09 18:22:34 +00:00
|
|
|
const window = await app.getWindow();
|
|
|
|
|
|
|
|
const leftPane = window.locator('.left-pane-wrapper');
|
|
|
|
|
|
|
|
const item = leftPane.locator(
|
2023-01-13 00:24:59 +00:00
|
|
|
`[data-testid="${lastContact?.toContact().uuid}"]`
|
2022-03-09 18:22:34 +00:00
|
|
|
);
|
|
|
|
await item.waitFor();
|
|
|
|
|
|
|
|
const duration = Date.now() - start;
|
|
|
|
console.log(`Took: ${(duration / 1000).toFixed(2)} seconds`);
|
|
|
|
} catch (error) {
|
2022-09-01 16:35:44 +00:00
|
|
|
await bootstrap.saveLogs(app);
|
2022-03-09 18:22:34 +00:00
|
|
|
throw error;
|
|
|
|
} finally {
|
2022-07-08 20:46:25 +00:00
|
|
|
await app?.close();
|
2022-03-09 18:22:34 +00:00
|
|
|
await bootstrap.teardown();
|
|
|
|
}
|
|
|
|
})();
|