test: speedup onion tests by stubbing retries timeout

pull/2873/head
Audric Ackermann 2 years ago
parent 51205424d6
commit 0ef2df801e

@ -236,7 +236,7 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
}, },
{ {
retries: 2, // retry 3 (2+1) times at most retries: 2, // retry 3 (2+1) times at most
minTimeout: 100, minTimeout: OnionSending.getMinTimeoutForSogs(),
onFailedAttempt: e => { onFailedAttempt: e => {
window?.log?.warn( window?.log?.warn(
`sendViaOnionV4ToNonSnodeRetryable attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...: ${e.message}` `sendViaOnionV4ToNonSnodeRetryable attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...: ${e.message}`
@ -525,6 +525,10 @@ async function sendJsonViaOnionV4ToFileServer(sendOptions: {
return res as OnionV4JSONSnodeResponse; return res as OnionV4JSONSnodeResponse;
} }
function getMinTimeoutForSogs() {
return 100;
}
// we export these methods for stubbing during testing // we export these methods for stubbing during testing
export const OnionSending = { export const OnionSending = {
endpointRequiresDecoding, endpointRequiresDecoding,
@ -536,4 +540,5 @@ export const OnionSending = {
sendBinaryViaOnionV4ToSogs, sendBinaryViaOnionV4ToSogs,
getBinaryViaOnionV4FromFileServer, getBinaryViaOnionV4FromFileServer,
sendJsonViaOnionV4ToFileServer, sendJsonViaOnionV4ToFileServer,
getMinTimeoutForSogs,
}; };

@ -134,7 +134,4 @@ describe('DecryptedAttachmentsManager', () => {
}); });
}); });
}); });
it.skip('cleanUpOldDecryptedMedias', () => {});
it.skip('getDecryptedBlob', () => {});
}); });

@ -259,7 +259,7 @@ describe('libsession_metagroup', () => {
); );
}); });
it('merging a key conflict marks needsRekey to true', () => { it.skip('merging a key conflict marks needsRekey to true', () => {
const metaGroupWrapper2 = new MetaGroupWrapperNode({ const metaGroupWrapper2 = new MetaGroupWrapperNode({
groupEd25519Pubkey: toFixedUint8ArrayOfLength( groupEd25519Pubkey: toFixedUint8ArrayOfLength(
HexString.fromHexString(groupCreated.pubkeyHex.slice(2)), HexString.fromHexString(groupCreated.pubkeyHex.slice(2)),
@ -269,20 +269,34 @@ describe('libsession_metagroup', () => {
metaDumped: null, metaDumped: null,
userEd25519Secretkey: toFixedUint8ArrayOfLength(us.ed25519KeyPair.privateKey, 64), userEd25519Secretkey: toFixedUint8ArrayOfLength(us.ed25519KeyPair.privateKey, 64),
}); });
metaGroupWrapper.memberSetPromoted(TestUtils.generateFakePubKeyStr(), false);
metaGroupWrapper2.memberSetPromoted(TestUtils.generateFakePubKeyStr(), false);
expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq(
false,
'rekey should be false on fresh group'
);
expect(metaGroupWrapper2.keysNeedsRekey()).to.be.eq(
false,
'rekey should be false on fresh group2'
);
const wrapper2Rekeyed = metaGroupWrapper2.keyRekey();
const loadedKey = metaGroupWrapper.loadKeyMessage('fakehash1', wrapper2Rekeyed, Date.now()); // mark current user as admin
expect(loadedKey).to.be.eq(true, 'key should have been loaded'); metaGroupWrapper.memberSetPromoted(us.x25519KeyPair.pubkeyHex, false);
metaGroupWrapper2.memberSetPromoted(us.x25519KeyPair.pubkeyHex, false);
// add 2 normal members to each of those wrappers
const m1 = TestUtils.generateFakePubKeyStr();
const m2 = TestUtils.generateFakePubKeyStr();
metaGroupWrapper.memberSetAccepted(m1);
metaGroupWrapper.memberSetAccepted(m2);
metaGroupWrapper2.memberSetAccepted(m1);
metaGroupWrapper2.memberSetAccepted(m2);
expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq(false);
expect(metaGroupWrapper2.keysNeedsRekey()).to.be.eq(false);
// remove m2 from wrapper2, and m1 from wrapper1
metaGroupWrapper2.memberErase(m2);
metaGroupWrapper.memberErase(m1);
// const push1 = metaGroupWrapper.push();
// metaGroupWrapper2.metaMerge([push1]);
// const wrapper2Rekeyed = metaGroupWrapper2.keyRekey();
// metaGroupWrapper.keyRekey();
// const loadedKey = metaGroupWrapper.loadKeyMessage('fakehash1', wrapper2Rekeyed, Date.now());
// expect(loadedKey).to.be.eq(true, 'key should have been loaded');
expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq( expect(metaGroupWrapper.keysNeedsRekey()).to.be.eq(
true, true,
'rekey should be true for after add' 'rekey should be true for after add'

@ -267,6 +267,7 @@ describe('MessageSender', () => {
bodyBinary: new Uint8Array(), bodyBinary: new Uint8Array(),
bodyContentType: 'a', bodyContentType: 'a',
}); });
Sinon.stub(OnionSending, 'getMinTimeoutForSogs').returns(5);
const message = TestUtils.generateOpenGroupVisibleMessage(); const message = TestUtils.generateOpenGroupVisibleMessage();
const roomInfos = TestUtils.generateOpenGroupV2RoomInfos(); const roomInfos = TestUtils.generateOpenGroupV2RoomInfos();
@ -279,6 +280,8 @@ describe('MessageSender', () => {
const roomInfos = TestUtils.generateOpenGroupV2RoomInfos(); const roomInfos = TestUtils.generateOpenGroupV2RoomInfos();
Sinon.stub(Onions, 'sendOnionRequestHandlingSnodeEject').resolves({} as any); Sinon.stub(Onions, 'sendOnionRequestHandlingSnodeEject').resolves({} as any);
Sinon.stub(OnionSending, 'getMinTimeoutForSogs').returns(5);
const decodev4responseStub = Sinon.stub(OnionV4, 'decodeV4Response'); const decodev4responseStub = Sinon.stub(OnionV4, 'decodeV4Response');
decodev4responseStub.throws('whate'); decodev4responseStub.throws('whate');
@ -296,6 +299,7 @@ describe('MessageSender', () => {
const message = TestUtils.generateOpenGroupVisibleMessage(); const message = TestUtils.generateOpenGroupVisibleMessage();
const roomInfos = TestUtils.generateOpenGroupV2RoomInfos(); const roomInfos = TestUtils.generateOpenGroupV2RoomInfos();
Sinon.stub(Onions, 'sendOnionRequestHandlingSnodeEject').resolves({} as any); Sinon.stub(Onions, 'sendOnionRequestHandlingSnodeEject').resolves({} as any);
Sinon.stub(OnionSending, 'getMinTimeoutForSogs').returns(5);
const decodev4responseStub = Sinon.stub(OnionV4, 'decodeV4Response'); const decodev4responseStub = Sinon.stub(OnionV4, 'decodeV4Response');
decodev4responseStub.throws('whate'); decodev4responseStub.throws('whate');

@ -18,6 +18,7 @@ describe('Updater', () => {
); );
} }
}); });
it('stubWindowLog is set to false before pushing', () => { it('stubWindowLog is set to false before pushing', () => {
expect(enableLogRedirect).to.be.eq( expect(enableLogRedirect).to.be.eq(
false, false,

@ -488,10 +488,6 @@ export const MetaGroupWrapperActions: MetaGroupWrapperActionsCalls = {
callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'keysNeedsRekey']) as Promise< callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'keysNeedsRekey']) as Promise<
ReturnType<MetaGroupWrapperActionsCalls['keysNeedsRekey']> ReturnType<MetaGroupWrapperActionsCalls['keysNeedsRekey']>
>, >,
groupKeys: async (groupPk: GroupPubkeyType) =>
callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'groupKeys']) as Promise<
ReturnType<MetaGroupWrapperActionsCalls['groupKeys']>
>,
currentHashes: async (groupPk: GroupPubkeyType) => currentHashes: async (groupPk: GroupPubkeyType) =>
callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'currentHashes']) as Promise< callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'currentHashes']) as Promise<
ReturnType<MetaGroupWrapperActionsCalls['currentHashes']> ReturnType<MetaGroupWrapperActionsCalls['currentHashes']>

Loading…
Cancel
Save