Skip to content

Commit 229832f

Browse files
author
Greg Soltis
authored
Stop saving persistence layer across spec tests (#1129)
* Add no-memory-persistence flag to spec tests. * Restart persistence for spec tests * [AUTOMATED]: Prettier Code Styling * No more negative tags * [AUTOMATED]: Prettier Code Styling * Put back the no-platform tags * [AUTOMATED]: Prettier Code Styling
1 parent 14f9a71 commit 229832f

File tree

6 files changed

+94
-76
lines changed

6 files changed

+94
-76
lines changed

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import { SpecStep } from './spec_test_runner';
2424
// Disables all other tests; useful for debugging. Multiple tests can have
2525
// this tag and they'll all be run (but all others won't).
2626
const EXCLUSIVE_TAG = 'exclusive';
27-
// Multi-client related tests (which imply persistence).
28-
const MULTI_CLIENT_TAG = 'multi-client';
2927
// Explicit per-platform disable flags.
3028
const NO_WEB_TAG = 'no-web';
3129
const NO_ANDROID_TAG = 'no-android';
3230
const NO_IOS_TAG = 'no-ios';
33-
const NO_LRU_TAG = 'no-lru';
31+
// The remaining tags specify features that must be present to run a given test
32+
// Multi-client related tests (which imply persistence).
33+
const MULTI_CLIENT_TAG = 'multi-client';
34+
const EAGER_GC_TAG = 'eager-gc';
35+
const DURABLE_PERSISTENCE_TAG = 'durable-persistence';
3436
const BENCHMARK_TAG = 'benchmark';
3537
const KNOWN_TAGS = [
3638
BENCHMARK_TAG,
@@ -39,7 +41,8 @@ const KNOWN_TAGS = [
3941
NO_WEB_TAG,
4042
NO_ANDROID_TAG,
4143
NO_IOS_TAG,
42-
NO_LRU_TAG
44+
EAGER_GC_TAG,
45+
DURABLE_PERSISTENCE_TAG
4346
];
4447

4548
// TOOD(mrschmidt): Make this configurable with mocha options.
@@ -78,7 +81,13 @@ export function setSpecJSONHandler(writer: (json: string) => void): void {
7881
function getTestRunner(tags, persistenceEnabled): Function {
7982
if (tags.indexOf(NO_WEB_TAG) >= 0) {
8083
return it.skip;
81-
} else if (persistenceEnabled && tags.indexOf(NO_LRU_TAG) !== -1) {
84+
} else if (
85+
!persistenceEnabled &&
86+
tags.indexOf(DURABLE_PERSISTENCE_TAG) !== -1
87+
) {
88+
// Test requires actual persistence, but it's not enabled. Skip it.
89+
return it.skip;
90+
} else if (persistenceEnabled && tags.indexOf(EAGER_GC_TAG) !== -1) {
8291
// spec should have a comment explaining why it is being skipped.
8392
return it.skip;
8493
} else if (!persistenceEnabled && tags.indexOf(MULTI_CLIENT_TAG) !== -1) {

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

+28-24
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describeSpec('Listens:', [], () => {
2727
// Obviously this test won't hold with offline persistence enabled.
2828
specTest(
2929
'Contents of query are cleared when listen is removed.',
30-
['no-lru'],
30+
['eager-gc'],
3131
'Explicitly tests eager GC behavior',
3232
() => {
3333
const query = Query.atPath(path('collection'));
@@ -228,7 +228,7 @@ describeSpec('Listens:', [], () => {
228228
// This would only happen when we use a resume token, but omitted for brevity.
229229
specTest(
230230
'Will gracefully handle watch stream reverting snapshots (with restart)',
231-
[],
231+
['durable-persistence'],
232232
() => {
233233
const query = Query.atPath(path('collection'));
234234
const docAv1 = doc('collection/a', 1000, { v: 'v1000' });
@@ -570,34 +570,38 @@ describeSpec('Listens:', [], () => {
570570
);
571571
});
572572

573-
specTest('Omits global resume tokens for a short while', [], () => {
574-
const query = Query.atPath(path('collection'));
575-
const docA = doc('collection/a', 1000, { key: 'a' });
573+
specTest(
574+
'Omits global resume tokens for a short while',
575+
['durable-persistence'],
576+
() => {
577+
const query = Query.atPath(path('collection'));
578+
const docA = doc('collection/a', 1000, { key: 'a' });
576579

577-
return (
578-
spec()
579-
.withGCEnabled(false)
580-
.userListens(query)
581-
.watchAcksFull(query, 1000, docA)
582-
.expectEvents(query, { added: [docA] })
580+
return (
581+
spec()
582+
.withGCEnabled(false)
583+
.userListens(query)
584+
.watchAcksFull(query, 1000, docA)
585+
.expectEvents(query, { added: [docA] })
583586

584-
// One millisecond later, watch sends an updated resume token but the
585-
// user doesn't manage to unlisten before restart.
586-
.watchSnapshots(2000, [], 'resume-token-2000')
587-
.restart()
587+
// One millisecond later, watch sends an updated resume token but the
588+
// user doesn't manage to unlisten before restart.
589+
.watchSnapshots(2000, [], 'resume-token-2000')
590+
.restart()
588591

589-
.userListens(query, 'resume-token-1000')
590-
.expectEvents(query, { added: [docA], fromCache: true })
591-
.watchAcks(query)
592-
.watchCurrents(query, 'resume-token-3000')
593-
.watchSnapshots(3000)
594-
.expectEvents(query, { fromCache: false })
595-
);
596-
});
592+
.userListens(query, 'resume-token-1000')
593+
.expectEvents(query, { added: [docA], fromCache: true })
594+
.watchAcks(query)
595+
.watchCurrents(query, 'resume-token-3000')
596+
.watchSnapshots(3000)
597+
.expectEvents(query, { fromCache: false })
598+
);
599+
}
600+
);
597601

598602
specTest(
599603
'Persists global resume tokens if the snapshot is old enough',
600-
[],
604+
['durable-persistence'],
601605
() => {
602606
const initialVersion = 1000;
603607
const minutesLater = 5 * 60 * 1e6 + initialVersion;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describeSpec('Offline:', [], () => {
6161

6262
specTest(
6363
'Removing all listeners delays "Offline" status on next listen',
64-
['no-lru'],
64+
['eager-gc'],
6565
'Marked as no-lru because when a listen is re-added, it gets a new target id rather than reusing one',
6666
() => {
6767
const query = Query.atPath(path('collection'));

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

+47-39
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,56 @@ import { client, spec } from './spec_builder';
2222
import { TimerId } from '../../../src/util/async_queue';
2323

2424
describeSpec('Persistence:', [], () => {
25-
specTest('Local mutations are persisted and re-sent', [], () => {
26-
return spec()
27-
.userSets('collection/key1', { foo: 'bar' })
28-
.userSets('collection/key2', { baz: 'quu' })
29-
.restart()
30-
.expectNumOutstandingWrites(2)
31-
.writeAcks('collection/key1', 1, { expectUserCallback: false })
32-
.writeAcks('collection/key2', 2, { expectUserCallback: false })
33-
.expectNumOutstandingWrites(0);
34-
});
35-
36-
specTest('Persisted local mutations are visible to listeners', [], () => {
37-
const query = Query.atPath(path('collection'));
38-
return (
39-
spec()
25+
specTest(
26+
'Local mutations are persisted and re-sent',
27+
['durable-persistence'],
28+
() => {
29+
return spec()
4030
.userSets('collection/key1', { foo: 'bar' })
4131
.userSets('collection/key2', { baz: 'quu' })
4232
.restart()
43-
// It should be visible to listens.
44-
.userListens(query)
45-
.expectEvents(query, {
46-
added: [
47-
doc(
48-
'collection/key1',
49-
0,
50-
{ foo: 'bar' },
51-
{ hasLocalMutations: true }
52-
),
53-
doc(
54-
'collection/key2',
55-
0,
56-
{ baz: 'quu' },
57-
{ hasLocalMutations: true }
58-
)
59-
],
60-
fromCache: true,
61-
hasPendingWrites: true
62-
})
63-
);
64-
});
33+
.expectNumOutstandingWrites(2)
34+
.writeAcks('collection/key1', 1, { expectUserCallback: false })
35+
.writeAcks('collection/key2', 2, { expectUserCallback: false })
36+
.expectNumOutstandingWrites(0);
37+
}
38+
);
39+
40+
specTest(
41+
'Persisted local mutations are visible to listeners',
42+
['durable-persistence'],
43+
() => {
44+
const query = Query.atPath(path('collection'));
45+
return (
46+
spec()
47+
.userSets('collection/key1', { foo: 'bar' })
48+
.userSets('collection/key2', { baz: 'quu' })
49+
.restart()
50+
// It should be visible to listens.
51+
.userListens(query)
52+
.expectEvents(query, {
53+
added: [
54+
doc(
55+
'collection/key1',
56+
0,
57+
{ foo: 'bar' },
58+
{ hasLocalMutations: true }
59+
),
60+
doc(
61+
'collection/key2',
62+
0,
63+
{ baz: 'quu' },
64+
{ hasLocalMutations: true }
65+
)
66+
],
67+
fromCache: true,
68+
hasPendingWrites: true
69+
})
70+
);
71+
}
72+
);
6573

66-
specTest('Remote documents are persisted', [], () => {
74+
specTest('Remote documents are persisted', ['durable-persistence'], () => {
6775
const query = Query.atPath(path('collection'));
6876
const doc1 = doc('collection/key', 1000, { foo: 'bar' });
6977
return spec()
@@ -126,7 +134,7 @@ describeSpec('Persistence:', [], () => {
126134

127135
specTest(
128136
'Mutation Queue is persisted across uid switches (with restarts)',
129-
[],
137+
['durable-persistence'],
130138
() => {
131139
return spec()
132140
.userSets('users/anon', { uid: 'anon' })

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,6 @@ abstract class TestRunner {
418418

419419
async start(): Promise<void> {
420420
this.persistence = await this.initPersistence(this.serializer);
421-
await this.init();
422-
}
423-
424-
private async init(): Promise<void> {
425421
const garbageCollector = this.getGarbageCollector();
426422

427423
this.sharedClientState = this.getSharedClientState();
@@ -872,13 +868,14 @@ abstract class TestRunner {
872868
}
873869

874870
private async doRestart(): Promise<void> {
875-
// Reinitialize everything, except the persistence.
871+
// Reinitialize everything.
876872
// No local store to shutdown.
877873
await this.remoteStore.shutdown();
874+
await this.persistence.shutdown(/* deleteData= */ false);
878875

879876
// We have to schedule the starts, otherwise we could end up with
880877
// interleaved events.
881-
await this.queue.enqueue(() => this.init());
878+
await this.queue.enqueue(() => this.start());
882879
}
883880

884881
private async doApplyClientState(state: SpecClientState): Promise<void> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ describeSpec('Writes:', [], () => {
455455

456456
specTest(
457457
'Held writes are released when there are no queries left.',
458-
['no-lru'],
458+
['eager-gc'],
459459
'This test expects a new target id for a new listen, but without eager gc, the same target id is reused',
460460
() => {
461461
const query = Query.atPath(path('collection'));

0 commit comments

Comments
 (0)