2022-04-13 00:50:17 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import { Proto } from '@signalapp/mock-server';
|
|
|
|
|
|
|
|
import * as durations from '../../util/durations';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2022-04-13 00:50:17 +00:00
|
|
|
import { MAX_READ_KEYS } from '../../services/storageConstants';
|
|
|
|
import type { App, Bootstrap } from './fixtures';
|
|
|
|
import { initStorage, debug } from './fixtures';
|
|
|
|
|
|
|
|
const IdentifierType = Proto.ManifestRecord.Identifier.Type;
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
describe('storage service', function (this: Mocha.Suite) {
|
2022-04-13 00:50:17 +00:00
|
|
|
this.timeout(durations.MINUTE);
|
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
({ bootstrap, app } = await initStorage());
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
afterEach(async function (this: Mocha.Context) {
|
2022-07-08 20:46:25 +00:00
|
|
|
if (!bootstrap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-14 16:53:20 +00:00
|
|
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
2022-04-13 00:50:17 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should receive all contacts despite low read keys limit', async () => {
|
|
|
|
debug('prepare for a slow test');
|
|
|
|
|
|
|
|
const { phone, contacts } = bootstrap;
|
|
|
|
const firstContact = contacts[0];
|
|
|
|
const lastContact = contacts[contacts.length - 1];
|
|
|
|
|
|
|
|
const window = await app.getWindow();
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const leftPane = window.locator('#LeftPane');
|
2022-04-13 00:50:17 +00:00
|
|
|
|
|
|
|
debug('wait for first contact to be pinned in the left pane');
|
|
|
|
await leftPane
|
2023-08-16 20:54:39 +00:00
|
|
|
.locator(`[data-testid="${firstContact.toContact().aci}"]`)
|
2022-04-13 00:50:17 +00:00
|
|
|
.waitFor();
|
|
|
|
|
|
|
|
{
|
|
|
|
let state = await phone.expectStorageState('consistency check');
|
|
|
|
|
|
|
|
debug('generating a lot of fake contacts');
|
|
|
|
for (let i = 0; i < MAX_READ_KEYS + 1; i += 1) {
|
|
|
|
state = state.addRecord({
|
|
|
|
type: IdentifierType.CONTACT,
|
|
|
|
record: {
|
|
|
|
contact: {
|
2023-08-16 20:54:39 +00:00
|
|
|
aci: generateAci(),
|
2022-04-13 00:50:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('pinning last contact');
|
|
|
|
state = state.pin(lastContact);
|
|
|
|
|
|
|
|
await phone.setStorageState(state);
|
|
|
|
|
|
|
|
debug('sending fetch storage');
|
|
|
|
await phone.sendFetchStorage({
|
|
|
|
timestamp: bootstrap.getTimestamp(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('wait for last contact to be pinned in the left pane');
|
|
|
|
await leftPane
|
2023-08-16 20:54:39 +00:00
|
|
|
.locator(`[data-testid="${lastContact.toContact().aci}"]`)
|
2022-04-13 00:50:17 +00:00
|
|
|
.waitFor({ timeout: durations.MINUTE });
|
|
|
|
|
|
|
|
debug('Verifying the final manifest version');
|
|
|
|
const finalState = await phone.expectStorageState('consistency check');
|
|
|
|
|
|
|
|
assert.strictEqual(finalState.version, 2);
|
|
|
|
});
|
|
|
|
});
|