Skip to content
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
85 changes: 49 additions & 36 deletions handwritten/firestore/dev/system-test/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ import * as chaiAsPromised from 'chai-as-promised';

import {afterEach, describe, it} from 'mocha';
import '../test/util/mocha_extensions';
import {verifyInstance} from '../test/util/helpers';
import {verifyInstance, isRest} from '../test/util/helpers';
import {getTestDb, getTestRoot} from './firestore';

import {Firestore as InternalFirestore} from '../src';
Expand Down Expand Up @@ -395,9 +395,9 @@ describe.skipClassic('Pipeline class', () => {
expectResults(deleteRes, {documents_modified: 1});
});

await promise;
const docSnap = await dmlCol.doc('book2').get();
expect(docSnap.exists).to.be.false;
await expect(promise).to.be.rejectedWith(
/Transactional DML operations are not yet supported/,
);
});

it('can execute update stage with addFields', async () => {
Expand Down Expand Up @@ -616,7 +616,10 @@ describe.skipClassic('Pipeline class', () => {
});

describe('pipeline explain', () => {
it('mode: analyze, format: text', async () => {
it('mode: analyze, format: text', async function () {
if (isRest(firestore)) {
this.skip();
}
const ppl = firestore
.pipeline()
.collection(randomCol.path)
Expand Down Expand Up @@ -656,7 +659,10 @@ describe.skipClassic('Pipeline class', () => {
);
});

it('mode: analyze, format: unspecified', async () => {
it('mode: analyze, format: unspecified', async function () {
if (isRest(firestore)) {
this.skip();
}
const ppl = firestore
.pipeline()
.collection(randomCol.path)
Expand Down Expand Up @@ -1862,15 +1868,18 @@ describe.skipClassic('Pipeline class', () => {
} catch (e: unknown) {
expect(e instanceof Error).to.be.true;
const err = e as ServiceError;
expect(err['code']).to.equal(3);
const isRestTest = isRest(firestore);
const expectedCode = isRestTest ? 400 : 3;
expect(err['code']).to.equal(expectedCode);
expect(typeof err['message']).to.equal('string');
expect(typeof err['details']).to.equal('string');
if (!isRestTest) {
expect(typeof err['details']).to.equal('string');
expect(err['message']).to.equal(
`${err.code} INVALID_ARGUMENT: ${err.details}`,
);
expect(err['metadata'] instanceof Object).to.be.true;
}
expect(typeof err['stack']).to.equal('string');
expect(err['metadata'] instanceof Object).to.be.true;

expect(err['message']).to.equal(
`${err.code} INVALID_ARGUMENT: ${err.details}`,
);
}
});

Expand All @@ -1894,29 +1903,32 @@ describe.skipClassic('Pipeline class', () => {
const err = e as {[k: string]: unknown};
expect(err instanceof Error).to.be.true;

expect(err['code']).to.equal(8);
const isRestTest = isRest(firestore);
const expectedCode = isRestTest ? 429 : 8;
expect(err['code']).to.equal(expectedCode);
expect(typeof err['message']).to.equal('string');
expect(typeof err['details']).to.equal('string');
expect(typeof err['stack']).to.equal('string');
expect(err['metadata'] instanceof Object).to.be.true;

expect(err['message']).to.equal(
`${err.code} RESOURCE_EXHAUSTED: ${err.details}`,
);
if (!isRestTest) {
expect(typeof err['details']).to.equal('string');
expect(err['message']).to.equal(
`${err.code} RESOURCE_EXHAUSTED: ${err.details}`,
);

expect('statusDetails' in err).to.be.true;
expect(Array.isArray(err['statusDetails'])).to.be.true;
expect('statusDetails' in err).to.be.true;
expect(Array.isArray(err['statusDetails'])).to.be.true;

const statusDetails = err['statusDetails'] as Array<object>;
const statusDetails = err['statusDetails'] as Array<object>;

const foundExplainStats = statusDetails.find(x => {
return (
'type_url' in x &&
x['type_url'] ===
'type.googleapis.com/google.firestore.v1.ExplainStats'
);
});
expect(foundExplainStats).to.not.be.undefined;
const foundExplainStats = statusDetails.find(x => {
return (
'type_url' in x &&
x['type_url'] ===
'type.googleapis.com/google.firestore.v1.ExplainStats'
);
});
expect(foundExplainStats).to.not.be.undefined;
expect(err['metadata'] instanceof Object).to.be.true;
}
expect(typeof err['stack']).to.equal('string');
}
});
});
Expand Down Expand Up @@ -7393,9 +7405,9 @@ describe.skipClassic('Pipeline search', () => {
// queryEnhancement: 'disabled'
});

await expect(ppl.execute()).to.be.rejectedWith(
/3 INVALID_ARGUMENT.*/,
);
const isRestTest = isRest(firestore);
const expectedErrorPattern = isRestTest ? /"code": 400/ : /3 INVALID_ARGUMENT.*/;
await expect(ppl.execute()).to.be.rejectedWith(expectedErrorPattern);
});
});

Expand Down Expand Up @@ -7446,7 +7458,8 @@ describe.skipClassic('Pipeline search', () => {
.search({...commonSearchParams, retrievalDepth: 1});

snapshot = await ppl.execute();
expectResults(snapshot, 'eastsideTacos');
expect(snapshot.results.length).to.equal(1);
expect(['solTacos', 'eastsideTacos']).to.include(snapshot.results[0].id);
});
});

Expand Down
40 changes: 23 additions & 17 deletions handwritten/firestore/dev/test/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,34 @@ export function createInstance(
* run.
*/
export function verifyInstance(firestore: Firestore): Promise<void> {
// Allow the setTimeout() call in _initializeStream to run before
// verifying that all operations have finished executing.
return new Promise<void>((resolve, reject) => {
if (firestore['_clientPool'].opCount === 0) {
resolve();
} else {
setTimeout(() => {
const opCount = firestore['_clientPool'].opCount;
if (opCount === 0) {
resolve();
} else {
reject(
new Error(
`Firestore has ${opCount} unfinished operations executing.`,
),
);
}
}, 10);
let attempts = 20; // 20 attempts * 50ms = 1000ms maximum wait
function check() {
const opCount = firestore['_clientPool'].opCount;
if (opCount === 0) {
resolve();
} else if (--attempts > 0) {
setTimeout(check, 50);
} else {
reject(
new Error(
`Firestore has ${opCount} unfinished operations executing.`,
),
);
}
}
check();
});
}

/**
* Helper function to check if testing is run using the REST backend.
* This inspects the internal preferRest setting on the given firestore instance.
*/
export function isRest(firestore: Firestore): boolean {
return !!(firestore as any)._settings?.preferRest;
}

function write(
document: api.IDocument,
mask: api.IDocumentMask | null,
Expand Down
8 changes: 4 additions & 4 deletions handwritten/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"predocs": "npm run compile",
"docs": "jsdoc -c .jsdoc.js",
"system-test:rest": "FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
"system-test:enterprise:rest": "FIRESTORE_DATABASE_ID=test-db FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
"system-test:enterprise:rest": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
"system-test:grpc": "mocha build/system-test --timeout 1200000",
"system-test:enterprise:grpc": "FIRESTORE_DATABASE_ID=test-db mocha build/system-test --timeout 1200000",
"system-test:enterprise:grpc": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise mocha build/system-test --timeout 1200000",
"system-test:emulator:rest": "FIRESTORE_EMULATOR_HOST=localhost:8080 FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
"system-test:enterprise:emulator:rest": "FIRESTORE_DATABASE_ID=test-db FIRESTORE_EMULATOR_HOST=localhost:8080 FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
"system-test:enterprise:emulator:rest": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise FIRESTORE_EMULATOR_HOST=localhost:8080 FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
"system-test:emulator:grpc": "FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
"system-test:enterprise:emulator:grpc": "FIRESTORE_DATABASE_ID=test-db FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
"system-test:enterprise:emulator:grpc": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
"system-test": "concurrently -p \"[{name}]\" -n \"grpc,rest,enterprise-grpc,enterprise-rest\" -c \"cyan,magenta,blue,yellow\" \"npm:system-test:grpc\" \"npm:system-test:rest\" \"npm:system-test:enterprise:grpc\" \"npm:system-test:enterprise:rest\"",
"system-test:nightly": "FIRESTORE_TARGET_BACKEND=nightly FIRESTORE_DATABASE_ID=enterprise RUN_ENTERPRISE_TESTS=yes GCLOUD_PROJECT=firestore-sdk-nightly mocha build/system-test --timeout 1200000",
"system-test:emulator": "concurrently -p \"[{name}]\" -n \"grpc,rest,enterprise-grpc,enterprise-rest\" -c \"cyan,magenta,blue,yellow\" \"npm:system-test:emulator:grpc\" \"npm:system-test:emulator:rest\" \"npm:system-test:enterprise:emulator:grpc\" \"npm:system-test:enterprise:emulator:rest\"",
Expand Down
Loading