make backfill limit explicit

This commit is contained in:
Bruno Windels 2021-09-23 10:10:22 +02:00
parent dd71fdbe08
commit 4b7cb6da9e

View file

@ -312,9 +312,9 @@ export function tests() {
}; };
} }
async function backfillAndWrite(mocks, fragmentEntry) { async function backfillAndWrite(mocks, fragmentEntry, limit) {
const {txn, timelineMock, gapWriter} = mocks; const {txn, timelineMock, gapWriter} = mocks;
const messageResponse = timelineMock.messages(fragmentEntry.token, undefined, fragmentEntry.direction.asApiString()); const messageResponse = timelineMock.messages(fragmentEntry.token, undefined, fragmentEntry.direction.asApiString(), limit);
await gapWriter.writeFragmentFill(fragmentEntry, messageResponse, txn, logger); await gapWriter.writeFragmentFill(fragmentEntry, messageResponse, txn, logger);
} }
@ -348,7 +348,7 @@ export function tests() {
const { timelineMock } = mocks; const { timelineMock } = mocks;
timelineMock.append(30); timelineMock.append(30);
const {fragmentEntry} = await syncAndWrite(mocks); const {fragmentEntry} = await syncAndWrite(mocks);
await backfillAndWrite(mocks, fragmentEntry); await backfillAndWrite(mocks, fragmentEntry, 10);
const events = await allFragmentEvents(mocks, fragmentEntry.fragmentId); const events = await allFragmentEvents(mocks, fragmentEntry.fragmentId);
assert.deepEqual(events.map(e => e.event_id), eventIds(10, 30)); assert.deepEqual(events.map(e => e.event_id), eventIds(10, 30));
await mocks.txn.complete(); await mocks.txn.complete();
@ -360,7 +360,7 @@ export function tests() {
const {syncResponse, fragmentEntry: firstFragmentEntry} = await syncAndWrite(mocks, { limit: 10 }); const {syncResponse, fragmentEntry: firstFragmentEntry} = await syncAndWrite(mocks, { limit: 10 });
timelineMock.append(15); timelineMock.append(15);
const {fragmentEntry: secondFragmentEntry} = await syncAndWrite(mocks, { previous: syncResponse, limit: 10 }); const {fragmentEntry: secondFragmentEntry} = await syncAndWrite(mocks, { previous: syncResponse, limit: 10 });
await backfillAndWrite(mocks, secondFragmentEntry); await backfillAndWrite(mocks, secondFragmentEntry, 10);
const firstFragment = await fetchFragment(mocks, firstFragmentEntry.fragmentId); const firstFragment = await fetchFragment(mocks, firstFragmentEntry.fragmentId);
const secondFragment = await fetchFragment(mocks, secondFragmentEntry.fragmentId); const secondFragment = await fetchFragment(mocks, secondFragmentEntry.fragmentId);
@ -378,7 +378,7 @@ export function tests() {
const {syncResponse, fragmentEntry: firstFragmentEntry} = await syncAndWrite(mocks, { limit: 10 }); const {syncResponse, fragmentEntry: firstFragmentEntry} = await syncAndWrite(mocks, { limit: 10 });
timelineMock.append(20); timelineMock.append(20);
const {fragmentEntry: secondFragmentEntry} = await syncAndWrite(mocks, { previous: syncResponse, limit: 10 }); const {fragmentEntry: secondFragmentEntry} = await syncAndWrite(mocks, { previous: syncResponse, limit: 10 });
await backfillAndWrite(mocks, secondFragmentEntry); await backfillAndWrite(mocks, secondFragmentEntry, 10);
const firstFragment = await fetchFragment(mocks, firstFragmentEntry.fragmentId); const firstFragment = await fetchFragment(mocks, firstFragmentEntry.fragmentId);
const secondFragment = await fetchFragment(mocks, secondFragmentEntry.fragmentId); const secondFragment = await fetchFragment(mocks, secondFragmentEntry.fragmentId);
@ -397,7 +397,7 @@ export function tests() {
// Mess with the saved token to receive old events in backfill // Mess with the saved token to receive old events in backfill
fragmentEntry.token = syncResponse.next_batch; fragmentEntry.token = syncResponse.next_batch;
txn.timelineFragments.update(fragmentEntry.fragment); txn.timelineFragments.update(fragmentEntry.fragment);
await backfillAndWrite(mocks, fragmentEntry); await backfillAndWrite(mocks, fragmentEntry, 10);
const fragment = await fetchFragment(mocks, fragmentEntry.fragmentId); const fragment = await fetchFragment(mocks, fragmentEntry.fragmentId);
assert.notEqual(fragment.nextId, fragment.id); assert.notEqual(fragment.nextId, fragment.id);
@ -412,7 +412,7 @@ export function tests() {
timelineMock.append(11); timelineMock.append(11);
const {fragmentEntry: secondFragmentEntry} = await syncAndWrite(mocks, { previous: syncResponse, limit: 10 }); const {fragmentEntry: secondFragmentEntry} = await syncAndWrite(mocks, { previous: syncResponse, limit: 10 });
timelineMock.insertAfter(eventId(9), 5); timelineMock.insertAfter(eventId(9), 5);
await backfillAndWrite(mocks, secondFragmentEntry); await backfillAndWrite(mocks, secondFragmentEntry, 10);
const firstEvents = await allFragmentEvents(mocks, firstFragmentEntry.fragmentId); const firstEvents = await allFragmentEvents(mocks, firstFragmentEntry.fragmentId);
assert.deepEqual(firstEvents.map(e => e.event_id), eventIds(0, 10)); assert.deepEqual(firstEvents.map(e => e.event_id), eventIds(0, 10));