Skip to content

Fix Spec tests 'Limbo documents stay consistent' #1994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/firestore/test/unit/specs/describe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const NO_ANDROID_TAG = 'no-android';
const NO_IOS_TAG = 'no-ios';
// The remaining tags specify features that must be present to run a given test
// Multi-client related tests (which imply persistence).
const MULTI_CLIENT_TAG = 'multi-client';
export const MULTI_CLIENT_TAG = 'multi-client';
const EAGER_GC_TAG = 'eager-gc';
const DURABLE_PERSISTENCE_TAG = 'durable-persistence';
const BENCHMARK_TAG = 'benchmark';
Expand Down Expand Up @@ -173,7 +173,7 @@ export function specTest(
const fullName = `${mode} ${name}`;
const queuedTest = runner(fullName, async () => {
const start = Date.now();
await spec.runAsTest(fullName, usePersistence);
await spec.runAsTest(fullName, tags, usePersistence);
const end = Date.now();
if (tags.indexOf(BENCHMARK_TAG) >= 0) {
// eslint-disable-next-line no-console
Expand Down
12 changes: 7 additions & 5 deletions packages/firestore/test/unit/specs/limbo_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,25 +439,27 @@ describeSpec('Limbo Documents:', [], () => {
// This tests verifies that a document is consistent between views, even
// if the document is only in Limbo in one of them.
const originalQuery = Query.atPath(path('collection'));
const filteredQuery = Query.atPath(path('collection'))
.addFilter(filter('matches', '==', true));
const filteredQuery = Query.atPath(path('collection')).addFilter(
filter('matches', '==', true)
);

const docA = doc('collection/a', 1000, { matches: true });
const docADirty = doc(
'collection/a',
1000,
{ matches: true },
{ matches: true },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. Strange that prettier allowed an extra space before...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't. But the change was never pushed.

{ hasCommittedMutations: true }
);
const docBDirty = doc(
'collection/b',
1001,
{ matches: true },
{ matches: true },
{ hasCommittedMutations: true }
);

return (
client(0)
spec()
.withGCEnabled(false)
.userSets('collection/a', { matches: true })
.userSets('collection/b', { matches: true })
.writeAcks('collection/a', 1000)
Expand Down
8 changes: 6 additions & 2 deletions packages/firestore/test/unit/specs/spec_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ export class SpecBuilder {
* Run the spec as a test. If persistence is available it will run it with and
* without persistence enabled.
*/
runAsTest(name: string, usePersistence: boolean): Promise<void> {
runAsTest(
name: string,
tags: string[],
usePersistence: boolean
): Promise<void> {
this.nextStep();
return runSpec(name, usePersistence, this.config, this.steps);
return runSpec(name, tags, usePersistence, this.config, this.steps);
}

// Configures Garbage Collection behavior (on or off). Default is on.
Expand Down
8 changes: 8 additions & 0 deletions packages/firestore/test/unit/specs/spec_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import {
TEST_PERSISTENCE_PREFIX,
TEST_SERIALIZER
} from '../local/persistence_test_helpers';
import { MULTI_CLIENT_TAG } from './describe_spec';

const ARBITRARY_SEQUENCE_NUMBER = 2;

Expand Down Expand Up @@ -1236,6 +1237,7 @@ class IndexedDbTestRunner extends TestRunner {
*/
export async function runSpec(
name: string,
tags: string[],
usePersistence: boolean,
config: SpecConfig,
steps: SpecStep[]
Expand Down Expand Up @@ -1279,6 +1281,12 @@ export async function runSpec(
let count = 0;
try {
await sequence(steps, async step => {
assert(
step.clientIndex === undefined || tags.indexOf(MULTI_CLIENT_TAG) !== -1,
"Cannot use 'client()' to initialize a test that is not tagged with " +
"'multi-client'. Did you mean to use 'spec()'?"
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it'd make sense to assert the inverse as well (if this is a multi-client test, then clientIndex must be defined)? Basically:

const isMultiClientTest = tags.indexOf(MULTI_CLIENT_TAG) !== -1;
const hasClientIndex = step.clientIndex !== undefined;
assert(isMultiClientTest === hasClientIndex, "Tests can use client() if-and-only-if they are tagged with 'multi-client'.");

I don't care strongly if that seems pointless though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not pointless, but not necessarily worth opening an IDE for and fixing since it would not break anything. I'll leave it as an imaginary TODO :)


++count;
lastStep = step;
return ensureRunner(step.clientIndex || 0).then(runner =>
Expand Down