speedup tests

pull/1512/head
Audric Ackermann 5 years ago
parent 8c4e071c00
commit 39f8ca293a
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -15,13 +15,9 @@ export const SessionRadio = (props: Props) => {
function clickHandler(e: any) { function clickHandler(e: any) {
e.stopPropagation(); e.stopPropagation();
console.warn(`SessionRadio clickHandler ${value}`);
onClick(value); onClick(value);
} }
console.warn(`isactive ${value}: ${active}`);
return ( return (
<Flex> <Flex>
<input <input

@ -15,7 +15,6 @@ export const SessionRadioGroup = (props: Props) => {
const { items, group, initialItem } = props; const { items, group, initialItem } = props;
useEffect(() => { useEffect(() => {
console.warn('unMNount:', initialItem);
setActiveItem(initialItem); setActiveItem(initialItem);
}, []); }, []);

@ -466,13 +466,6 @@ async function sendAddedMembers(
await ConversationController.getInstance().getOrCreateAndWait(m, 'private'); await ConversationController.getInstance().getOrCreateAndWait(m, 'private');
const memberPubKey = PubKey.cast(m); const memberPubKey = PubKey.cast(m);
await getMessageQueue().sendToPubKey(memberPubKey, newClosedGroupUpdate); await getMessageQueue().sendToPubKey(memberPubKey, newClosedGroupUpdate);
// if (expirationTimerMessage) {
// await getMessageQueue().sendToPubKey(
// memberPubKey,
// expirationTimerMessage
// );
// }
}); });
await Promise.all(promises); await Promise.all(promises);
} }

@ -26,7 +26,8 @@ export function canSendToSnode(): boolean {
*/ */
export async function send( export async function send(
message: RawMessage, message: RawMessage,
attempts: number = 3 attempts: number = 3,
retryMinTimeout?: number // in ms
): Promise<Uint8Array> { ): Promise<Uint8Array> {
if (!canSendToSnode()) { if (!canSendToSnode()) {
throw new Error('lokiMessageAPI is not initialized.'); throw new Error('lokiMessageAPI is not initialized.');
@ -56,6 +57,7 @@ export async function send(
{ {
retries: Math.max(attempts - 1, 0), retries: Math.max(attempts - 1, 0),
factor: 1, factor: 1,
minTimeout: retryMinTimeout || 1000,
} }
); );
} }

@ -39,7 +39,7 @@ describe('MessageQueue', () => {
let messageQueueStub: MessageQueue; let messageQueueStub: MessageQueue;
// Message Sender Stubs // Message Sender Stubs
let sendStub: sinon.SinonStub<[RawMessage, (number | undefined)?]>; let sendStub: sinon.SinonStub<[RawMessage, (number | undefined)?, (number | undefined)?]>;
beforeEach(() => { beforeEach(() => {
// Utils Stubs // Utils Stubs
@ -113,7 +113,7 @@ describe('MessageQueue', () => {
const promise = PromiseUtils.waitUntil(async () => { const promise = PromiseUtils.waitUntil(async () => {
const messages = await pendingMessageCache.getForDevice(device); const messages = await pendingMessageCache.getForDevice(device);
return messages.length === 0; return messages.length === 0;
}); }, 100);
return promise.should.be.fulfilled; return promise.should.be.fulfilled;
} }
}).timeout(15000); }).timeout(15000);
@ -122,45 +122,51 @@ describe('MessageQueue', () => {
it('should send a success event if message was sent', done => { it('should send a success event if message was sent', done => {
const device = TestUtils.generateFakePubKey(); const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage(); const message = TestUtils.generateChatMessage();
const waitForMessageSentEvent = new Promise(resolve => { const waitForMessageSentEvent = async () => new Promise<void>(resolve => {
resolve(true); resolve();
done(); try {
});
void pendingMessageCache
.add(device, message, waitForMessageSentEvent as any)
.then(() => messageQueueStub.processPending(device))
.then(() => {
expect(messageSentHandlerSuccessStub.callCount).to.be.equal(1); expect(messageSentHandlerSuccessStub.callCount).to.be.equal(1);
expect( expect(
messageSentHandlerSuccessStub.lastCall.args[0].identifier messageSentHandlerSuccessStub.lastCall.args[0].identifier
).to.be.equal(message.identifier); ).to.be.equal(message.identifier);
}); done();
} catch (e) {
done(e);
}
});
void pendingMessageCache
.add(device, message, waitForMessageSentEvent)
.then(() => messageQueueStub.processPending(device));
}); });
it('should send a fail event if something went wrong while sending', done => { it('should send a fail event if something went wrong while sending', async () => {
sendStub.throws(new Error('failure')); sendStub.throws(new Error('failure'));
const device = TestUtils.generateFakePubKey(); const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage(); const message = TestUtils.generateChatMessage();
const waitForMessageSentEvent = new Promise(resolve => {
resolve(true);
done();
});
void pendingMessageCache void pendingMessageCache
.add(device, message, waitForMessageSentEvent as any) .add(device, message)
.then(() => messageQueueStub.processPending(device)) .then(() => messageQueueStub.processPending(device));
.then(() => { // The cb is only invoke is all reties fails. Here we poll until the messageSentHandlerFailed was invoked as this is what we want to do
expect(messageSentHandlerFailedStub.callCount).to.be.equal(1);
expect( return PromiseUtils.poll(done => {
messageSentHandlerFailedStub.lastCall.args[0].identifier if (messageSentHandlerFailedStub.callCount === 1) {
).to.be.equal(message.identifier); try {
expect( expect(messageSentHandlerFailedStub.callCount).to.be.equal(1);
messageSentHandlerFailedStub.lastCall.args[1].message expect(
).to.equal('failure'); messageSentHandlerFailedStub.lastCall.args[0].identifier
expect(waitForMessageSentEvent).to.be.eventually.fulfilled; ).to.be.equal(message.identifier);
}); expect(
messageSentHandlerFailedStub.lastCall.args[1].message
).to.equal('failure');
done();
} catch (e) {
done(e);
}
}
});
}); });
}); });
}); });
@ -182,7 +188,7 @@ describe('MessageQueue', () => {
describe('sendToGroup', () => { describe('sendToGroup', () => {
it('should throw an error if invalid non-group message was passed', async () => { it('should throw an error if invalid non-group message was passed', async () => {
const chatMessage = TestUtils.generateChatMessage(); const chatMessage = TestUtils.generateChatMessage();
await expect( return expect(
messageQueueStub.sendToGroup(chatMessage as any) messageQueueStub.sendToGroup(chatMessage as any)
).to.be.rejectedWith('Invalid group message passed in sendToGroup.'); ).to.be.rejectedWith('Invalid group message passed in sendToGroup.');
}); });

@ -85,16 +85,19 @@ describe('MessageSender', () => {
}); });
it('should only retry the specified amount of times before throwing', async () => { it('should only retry the specified amount of times before throwing', async () => {
// const clock = sinon.useFakeTimers();
lokiMessageAPISendStub.throws(new Error('API error')); lokiMessageAPISendStub.throws(new Error('API error'));
const attempts = 2; const attempts = 2;
const promise = MessageSender.send(rawMessage, attempts); const promise = MessageSender.send(rawMessage, attempts, 10);
await expect(promise).is.rejectedWith('API error'); await expect(promise).is.rejectedWith('API error');
// clock.restore();
expect(lokiMessageAPISendStub.callCount).to.equal(attempts); expect(lokiMessageAPISendStub.callCount).to.equal(attempts);
}); });
it('should not throw error if successful send occurs within the retry limit', async () => { it('should not throw error if successful send occurs within the retry limit', async () => {
lokiMessageAPISendStub.onFirstCall().throws(new Error('API error')); lokiMessageAPISendStub.onFirstCall().throws(new Error('API error'));
await MessageSender.send(rawMessage, 3); await MessageSender.send(rawMessage, 3, 10);
expect(lokiMessageAPISendStub.callCount).to.equal(2); expect(lokiMessageAPISendStub.callCount).to.equal(2);
}); });
}); });

@ -17,7 +17,7 @@ describe('JobQueue', () => {
const id = 'jobId'; const id = 'jobId';
assert.isFalse(queue.has(id)); assert.isFalse(queue.has(id));
const promise = queue.addWithId(id, async () => TestUtils.timeout(100)); const promise = queue.addWithId(id, async () => TestUtils.timeout(30));
assert.isTrue(queue.has(id)); assert.isTrue(queue.has(id));
await promise; await promise;
assert.isFalse(queue.has(id)); assert.isFalse(queue.has(id));
@ -27,9 +27,9 @@ describe('JobQueue', () => {
describe('addWithId', () => { describe('addWithId', () => {
it('should run the jobs concurrently', async () => { it('should run the jobs concurrently', async () => {
const input = [ const input = [
[10, 300], [10, 10],
[20, 200], [20, 8],
[30, 100], [30, 2],
]; ];
const queue = new JobQueue(); const queue = new JobQueue();
const mapper = async ([value, ms]: Array<number>): Promise<number> => const mapper = async ([value, ms]: Array<number>): Promise<number> =>
@ -48,20 +48,20 @@ describe('JobQueue', () => {
const timeTaken = Date.now() - start; const timeTaken = Date.now() - start;
assert.isAtLeast( assert.isAtLeast(
timeTaken, timeTaken,
600, 20,
'Queue should take atleast 600ms to run.' 'Queue should take atleast 100ms to run.'
); );
}); });
it('should return the result of the job', async () => { it('should return the result of the job', async () => {
const queue = new JobQueue(); const queue = new JobQueue();
const success = queue.addWithId(uuid(), async () => { const success = queue.addWithId(uuid(), async () => {
await TestUtils.timeout(100); await TestUtils.timeout(10);
return 'success'; return 'success';
}); });
const failure = queue.addWithId(uuid(), async () => { const failure = queue.addWithId(uuid(), async () => {
await TestUtils.timeout(100); await TestUtils.timeout(10);
throw new Error('failed'); throw new Error('failed');
}); });
@ -73,7 +73,7 @@ describe('JobQueue', () => {
const queue = new JobQueue(); const queue = new JobQueue();
const first = queue.addWithId(uuid(), () => 'first'); const first = queue.addWithId(uuid(), () => 'first');
const second = queue.addWithId(uuid(), async () => { const second = queue.addWithId(uuid(), async () => {
await TestUtils.timeout(100); await TestUtils.timeout(10);
return 'second'; return 'second';
}); });
@ -90,7 +90,7 @@ describe('JobQueue', () => {
const queue = new JobQueue(); const queue = new JobQueue();
const id = uuid(); const id = uuid();
const job = async () => { const job = async () => {
await TestUtils.timeout(100); await TestUtils.timeout(10);
return 'job1'; return 'job1';
}; };
@ -106,14 +106,14 @@ describe('JobQueue', () => {
const id = uuid(); const id = uuid();
const successfullJob = queue.addWithId(id, async () => const successfullJob = queue.addWithId(id, async () =>
TestUtils.timeout(100) TestUtils.timeout(10)
); );
assert.isTrue(queue.has(id)); assert.isTrue(queue.has(id));
await successfullJob; await successfullJob;
assert.isFalse(queue.has(id)); assert.isFalse(queue.has(id));
const failJob = queue.addWithId(id, async () => { const failJob = queue.addWithId(id, async () => {
await TestUtils.timeout(100); await TestUtils.timeout(10);
throw new Error('failed'); throw new Error('failed');
}); });
assert.isTrue(queue.has(id)); assert.isTrue(queue.has(id));

@ -51,7 +51,7 @@ describe('Promise Utils', () => {
done(); done();
}; };
const promise = PromiseUtils.poll(task, {}); const promise = PromiseUtils.poll(task, { interval: 10 });
expect(pollSpy.callCount).to.equal(1); expect(pollSpy.callCount).to.equal(1);
expect(completionSpy.callCount).to.equal(1); expect(completionSpy.callCount).to.equal(1);
@ -63,7 +63,7 @@ describe('Promise Utils', () => {
const completionSpy = sandbox.spy(); const completionSpy = sandbox.spy();
const task = (_done: any) => undefined; const task = (_done: any) => undefined;
const promise = PromiseUtils.poll(task, { timeoutMs: 1 }); const promise = PromiseUtils.poll(task, { timeoutMs: 1, interval: 10 });
expect(pollSpy.callCount).to.equal(1); expect(pollSpy.callCount).to.equal(1);
expect(completionSpy.callCount).to.equal(0); expect(completionSpy.callCount).to.equal(0);
@ -75,7 +75,7 @@ describe('Promise Utils', () => {
it('will recur according to interval option', async () => { it('will recur according to interval option', async () => {
const expectedRecurrences = 4; const expectedRecurrences = 4;
const timeout = 3000; const timeout = 3000;
const interval = 50; const interval = 3;
const recurrenceSpy = sandbox.spy(); const recurrenceSpy = sandbox.spy();
const task = (done: any) => { const task = (done: any) => {
@ -129,7 +129,7 @@ describe('Promise Utils', () => {
describe('waitUntil', () => { describe('waitUntil', () => {
it('can wait for check', async () => { it('can wait for check', async () => {
const check = () => true; const check = () => true;
const promise = PromiseUtils.waitUntil(check); const promise = PromiseUtils.waitUntil(check, 5);
expect(waitUntilSpy.callCount).to.equal(1); expect(waitUntilSpy.callCount).to.equal(1);
return promise; return promise;

@ -1,14 +0,0 @@
import { assert } from 'chai';
import { keyPair, sign, verify } from '../../updater/curve';
describe('updater/curve', () => {
it('roundtrips', () => {
const message = Buffer.from('message');
const { publicKey, privateKey } = keyPair();
const signature = sign(privateKey, message);
const verified = verify(publicKey, message, signature);
assert.strictEqual(verified, true);
});
});
Loading…
Cancel
Save