Skip to content

Commit 20ff6e3

Browse files
Fix Spec tests 'Limbo documents stay consistent'
1 parent 3c8f85d commit 20ff6e3

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const NO_ANDROID_TAG = 'no-android';
3333
const NO_IOS_TAG = 'no-ios';
3434
// The remaining tags specify features that must be present to run a given test
3535
// Multi-client related tests (which imply persistence).
36-
const MULTI_CLIENT_TAG = 'multi-client';
36+
export const MULTI_CLIENT_TAG = 'multi-client';
3737
const EAGER_GC_TAG = 'eager-gc';
3838
const DURABLE_PERSISTENCE_TAG = 'durable-persistence';
3939
const BENCHMARK_TAG = 'benchmark';
@@ -173,7 +173,7 @@ export function specTest(
173173
const fullName = `${mode} ${name}`;
174174
const queuedTest = runner(fullName, async () => {
175175
const start = Date.now();
176-
await spec.runAsTest(fullName, usePersistence);
176+
await spec.runAsTest(fullName, tags, usePersistence);
177177
const end = Date.now();
178178
if (tags.indexOf(BENCHMARK_TAG) >= 0) {
179179
// eslint-disable-next-line no-console

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,25 +439,27 @@ describeSpec('Limbo Documents:', [], () => {
439439
// This tests verifies that a document is consistent between views, even
440440
// if the document is only in Limbo in one of them.
441441
const originalQuery = Query.atPath(path('collection'));
442-
const filteredQuery = Query.atPath(path('collection'))
443-
.addFilter(filter('matches', '==', true));
442+
const filteredQuery = Query.atPath(path('collection')).addFilter(
443+
filter('matches', '==', true)
444+
);
444445

445446
const docA = doc('collection/a', 1000, { matches: true });
446447
const docADirty = doc(
447448
'collection/a',
448449
1000,
449-
{ matches: true },
450+
{ matches: true },
450451
{ hasCommittedMutations: true }
451452
);
452453
const docBDirty = doc(
453454
'collection/b',
454455
1001,
455-
{ matches: true },
456+
{ matches: true },
456457
{ hasCommittedMutations: true }
457458
);
458459

459460
return (
460-
client(0)
461+
spec()
462+
.withGCEnabled(false)
461463
.userSets('collection/a', { matches: true })
462464
.userSets('collection/b', { matches: true })
463465
.writeAcks('collection/a', 1000)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,13 @@ export class SpecBuilder {
195195
* Run the spec as a test. If persistence is available it will run it with and
196196
* without persistence enabled.
197197
*/
198-
runAsTest(name: string, usePersistence: boolean): Promise<void> {
198+
runAsTest(
199+
name: string,
200+
tags: string[],
201+
usePersistence: boolean
202+
): Promise<void> {
199203
this.nextStep();
200-
return runSpec(name, usePersistence, this.config, this.steps);
204+
return runSpec(name, tags, usePersistence, this.config, this.steps);
201205
}
202206

203207
// Configures Garbage Collection behavior (on or off). Default is on.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import {
109109
TEST_PERSISTENCE_PREFIX,
110110
TEST_SERIALIZER
111111
} from '../local/persistence_test_helpers';
112+
import { MULTI_CLIENT_TAG } from './describe_spec';
112113

113114
const ARBITRARY_SEQUENCE_NUMBER = 2;
114115

@@ -1236,6 +1237,7 @@ class IndexedDbTestRunner extends TestRunner {
12361237
*/
12371238
export async function runSpec(
12381239
name: string,
1240+
tags: string[],
12391241
usePersistence: boolean,
12401242
config: SpecConfig,
12411243
steps: SpecStep[]
@@ -1279,6 +1281,12 @@ export async function runSpec(
12791281
let count = 0;
12801282
try {
12811283
await sequence(steps, async step => {
1284+
assert(
1285+
step.clientIndex === undefined || tags.indexOf(MULTI_CLIENT_TAG) != -1,
1286+
"Cannot use 'client()' to initialize a test that is not tagged with " +
1287+
"'multi-client'. Did you mean to use 'spec()'?"
1288+
);
1289+
12821290
++count;
12831291
lastStep = step;
12841292
return ensureRunner(step.clientIndex || 0).then(runner =>

0 commit comments

Comments
 (0)