Skip to content

Commit 4a075eb

Browse files
authored
test(firestore): update integration tests to use enterprise database (#8371)
1 parent 5968226 commit 4a075eb

3 files changed

Lines changed: 76 additions & 57 deletions

File tree

handwritten/firestore/dev/system-test/pipeline.ts

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ import * as chaiAsPromised from 'chai-as-promised';
180180

181181
import {afterEach, describe, it} from 'mocha';
182182
import '../test/util/mocha_extensions';
183-
import {verifyInstance} from '../test/util/helpers';
183+
import {verifyInstance, isRest} from '../test/util/helpers';
184184
import {getTestDb, getTestRoot} from './firestore';
185185

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

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

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

618618
describe('pipeline explain', () => {
619-
it('mode: analyze, format: text', async () => {
619+
it('mode: analyze, format: text', async function () {
620+
if (isRest(firestore)) {
621+
this.skip();
622+
}
620623
const ppl = firestore
621624
.pipeline()
622625
.collection(randomCol.path)
@@ -656,7 +659,10 @@ describe.skipClassic('Pipeline class', () => {
656659
);
657660
});
658661

659-
it('mode: analyze, format: unspecified', async () => {
662+
it('mode: analyze, format: unspecified', async function () {
663+
if (isRest(firestore)) {
664+
this.skip();
665+
}
660666
const ppl = firestore
661667
.pipeline()
662668
.collection(randomCol.path)
@@ -1862,15 +1868,18 @@ describe.skipClassic('Pipeline class', () => {
18621868
} catch (e: unknown) {
18631869
expect(e instanceof Error).to.be.true;
18641870
const err = e as ServiceError;
1865-
expect(err['code']).to.equal(3);
1871+
const isRestTest = isRest(firestore);
1872+
const expectedCode = isRestTest ? 400 : 3;
1873+
expect(err['code']).to.equal(expectedCode);
18661874
expect(typeof err['message']).to.equal('string');
1867-
expect(typeof err['details']).to.equal('string');
1875+
if (!isRestTest) {
1876+
expect(typeof err['details']).to.equal('string');
1877+
expect(err['message']).to.equal(
1878+
`${err.code} INVALID_ARGUMENT: ${err.details}`,
1879+
);
1880+
expect(err['metadata'] instanceof Object).to.be.true;
1881+
}
18681882
expect(typeof err['stack']).to.equal('string');
1869-
expect(err['metadata'] instanceof Object).to.be.true;
1870-
1871-
expect(err['message']).to.equal(
1872-
`${err.code} INVALID_ARGUMENT: ${err.details}`,
1873-
);
18741883
}
18751884
});
18761885

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

1897-
expect(err['code']).to.equal(8);
1906+
const isRestTest = isRest(firestore);
1907+
const expectedCode = isRestTest ? 429 : 8;
1908+
expect(err['code']).to.equal(expectedCode);
18981909
expect(typeof err['message']).to.equal('string');
1899-
expect(typeof err['details']).to.equal('string');
1900-
expect(typeof err['stack']).to.equal('string');
1901-
expect(err['metadata'] instanceof Object).to.be.true;
1902-
1903-
expect(err['message']).to.equal(
1904-
`${err.code} RESOURCE_EXHAUSTED: ${err.details}`,
1905-
);
1910+
if (!isRestTest) {
1911+
expect(typeof err['details']).to.equal('string');
1912+
expect(err['message']).to.equal(
1913+
`${err.code} RESOURCE_EXHAUSTED: ${err.details}`,
1914+
);
19061915

1907-
expect('statusDetails' in err).to.be.true;
1908-
expect(Array.isArray(err['statusDetails'])).to.be.true;
1916+
expect('statusDetails' in err).to.be.true;
1917+
expect(Array.isArray(err['statusDetails'])).to.be.true;
19091918

1910-
const statusDetails = err['statusDetails'] as Array<object>;
1919+
const statusDetails = err['statusDetails'] as Array<object>;
19111920

1912-
const foundExplainStats = statusDetails.find(x => {
1913-
return (
1914-
'type_url' in x &&
1915-
x['type_url'] ===
1916-
'type.googleapis.com/google.firestore.v1.ExplainStats'
1917-
);
1918-
});
1919-
expect(foundExplainStats).to.not.be.undefined;
1921+
const foundExplainStats = statusDetails.find(x => {
1922+
return (
1923+
'type_url' in x &&
1924+
x['type_url'] ===
1925+
'type.googleapis.com/google.firestore.v1.ExplainStats'
1926+
);
1927+
});
1928+
expect(foundExplainStats).to.not.be.undefined;
1929+
expect(err['metadata'] instanceof Object).to.be.true;
1930+
}
1931+
expect(typeof err['stack']).to.equal('string');
19201932
}
19211933
});
19221934
});
@@ -7393,9 +7405,9 @@ describe.skipClassic('Pipeline search', () => {
73937405
// queryEnhancement: 'disabled'
73947406
});
73957407

7396-
await expect(ppl.execute()).to.be.rejectedWith(
7397-
/3 INVALID_ARGUMENT.*/,
7398-
);
7408+
const isRestTest = isRest(firestore);
7409+
const expectedErrorPattern = isRestTest ? /"code": 400/ : /3 INVALID_ARGUMENT.*/;
7410+
await expect(ppl.execute()).to.be.rejectedWith(expectedErrorPattern);
73997411
});
74007412
});
74017413

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

74487460
snapshot = await ppl.execute();
7449-
expectResults(snapshot, 'eastsideTacos');
7461+
expect(snapshot.results.length).to.equal(1);
7462+
expect(['solTacos', 'eastsideTacos']).to.include(snapshot.results[0].id);
74507463
});
74517464
});
74527465

handwritten/firestore/dev/test/util/helpers.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,34 @@ export function createInstance(
9090
* run.
9191
*/
9292
export function verifyInstance(firestore: Firestore): Promise<void> {
93-
// Allow the setTimeout() call in _initializeStream to run before
94-
// verifying that all operations have finished executing.
9593
return new Promise<void>((resolve, reject) => {
96-
if (firestore['_clientPool'].opCount === 0) {
97-
resolve();
98-
} else {
99-
setTimeout(() => {
100-
const opCount = firestore['_clientPool'].opCount;
101-
if (opCount === 0) {
102-
resolve();
103-
} else {
104-
reject(
105-
new Error(
106-
`Firestore has ${opCount} unfinished operations executing.`,
107-
),
108-
);
109-
}
110-
}, 10);
94+
let attempts = 20; // 20 attempts * 50ms = 1000ms maximum wait
95+
function check() {
96+
const opCount = firestore['_clientPool'].opCount;
97+
if (opCount === 0) {
98+
resolve();
99+
} else if (--attempts > 0) {
100+
setTimeout(check, 50);
101+
} else {
102+
reject(
103+
new Error(
104+
`Firestore has ${opCount} unfinished operations executing.`,
105+
),
106+
);
107+
}
111108
}
109+
check();
112110
});
113111
}
114112

113+
/**
114+
* Helper function to check if testing is run using the REST backend.
115+
* This inspects the internal preferRest setting on the given firestore instance.
116+
*/
117+
export function isRest(firestore: Firestore): boolean {
118+
return !!(firestore as any)._settings?.preferRest;
119+
}
120+
115121
function write(
116122
document: api.IDocument,
117123
mask: api.IDocumentMask | null,

handwritten/firestore/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
"predocs": "npm run compile",
4141
"docs": "jsdoc -c .jsdoc.js",
4242
"system-test:rest": "FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
43-
"system-test:enterprise:rest": "FIRESTORE_DATABASE_ID=test-db FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
43+
"system-test:enterprise:rest": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
4444
"system-test:grpc": "mocha build/system-test --timeout 1200000",
45-
"system-test:enterprise:grpc": "FIRESTORE_DATABASE_ID=test-db mocha build/system-test --timeout 1200000",
45+
"system-test:enterprise:grpc": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise mocha build/system-test --timeout 1200000",
4646
"system-test:emulator:rest": "FIRESTORE_EMULATOR_HOST=localhost:8080 FIRESTORE_PREFER_REST=true mocha build/system-test --timeout 1200000",
47-
"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",
47+
"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",
4848
"system-test:emulator:grpc": "FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
49-
"system-test:enterprise:emulator:grpc": "FIRESTORE_DATABASE_ID=test-db FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
49+
"system-test:enterprise:emulator:grpc": "RUN_ENTERPRISE_TESTS=yes FIRESTORE_DATABASE_ID=enterprise FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
5050
"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\"",
5151
"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",
5252
"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\"",

0 commit comments

Comments
 (0)