Skip to content

Commit 5c485dc

Browse files
Add Watch update perf test (#1059)
1 parent 6abb55f commit 5c485dc

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

packages/firestore/test/unit/specs/perf_spec.test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { Query } from '../../../src/core/query';
18-
import { doc, orderBy, path } from '../../util/helpers';
18+
import { doc, filter, orderBy, path } from '../../util/helpers';
1919

2020
import { describeSpec, specTest } from './describe_spec';
2121
import { spec } from './spec_builder';
@@ -238,5 +238,52 @@ describeSpec(
238238
return steps;
239239
}
240240
);
241+
242+
specTest('Process 25 target updates and wait for snapshot', [], () => {
243+
const queriesPerStep = 25;
244+
245+
let currentVersion = 1;
246+
let steps = spec().withGCEnabled(false);
247+
248+
for (let i = 1; i <= STEP_COUNT; ++i) {
249+
// We use a different subcollection for each iteration to ensure
250+
// that we use distinct and non-overlapping collection queries.
251+
const collPath = `collection/${i}/coll`;
252+
const matchingDoc = doc(`${collPath}/matches`, ++currentVersion, {
253+
val: -1
254+
});
255+
256+
const queries = [];
257+
258+
// Create `queriesPerStep` listens, each against collPath but with a
259+
// unique query constraint.
260+
for (let j = 0; j < queriesPerStep; ++j) {
261+
const query = Query.atPath(path(collPath)).addFilter(
262+
filter('val', '<=', j)
263+
);
264+
queries.push(query);
265+
steps = steps.userListens(query).watchAcks(query);
266+
}
267+
268+
steps = steps
269+
.watchSends({ affects: queries }, matchingDoc)
270+
.watchSnapshots(++currentVersion);
271+
272+
// Registers the snapshot expectations with the spec runner.
273+
for (const query of queries) {
274+
steps = steps.expectEvents(query, {
275+
added: [matchingDoc],
276+
fromCache: true
277+
});
278+
}
279+
280+
// Unlisten and clean up the query.
281+
for (const query of queries) {
282+
steps = steps.userUnlistens(query).watchRemoves(query);
283+
}
284+
}
285+
286+
return steps;
287+
});
241288
}
242289
);

0 commit comments

Comments
 (0)