Skip to content

Commit 77e84c6

Browse files
committed
test: run system tests in parallel and fix collection name conflicts
1 parent 4e5752b commit 77e84c6

3 files changed

Lines changed: 35 additions & 29 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,8 @@ describe('DocumentReference class', () => {
17411741
},
17421742
};
17431743

1744-
const coll = firestore.collection('tests');
1744+
const coll = firestore.collection('node_tests_' + autoId());
1745+
17451746
const ref = coll.doc('number').withConverter(primitiveConverter);
17461747
await ref.set(3);
17471748
const result = await ref.get();
@@ -7436,7 +7437,8 @@ describe('BulkWriter class', () => {
74367437
// TODO enterprise b/469490062
74377438
it.skipEnterprise('does not affect other collections', async () => {
74387439
// Add other nested collection that shouldn't be deleted.
7439-
const collB = firestore.collection('doggos');
7440+
const collB = firestore.collection('node_doggos_' + autoId());
7441+
74407442
await collB.doc('doggo').set({name: 'goodboi'});
74417443

74427444
await firestore.recursiveDelete(collB);

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import {
4141
SpanProcessor,
4242
TimedEvent,
4343
} from '@opentelemetry/sdk-trace-node';
44-
import {setLogFunction, Firestore} from '../src';
44+
import {setLogFunction, Firestore, CollectionReference} from '../src';
45+
import {autoId} from '../src/util';
4546
import {verifyInstance} from '../test/util/helpers';
4647
import {
4748
ATTRIBUTE_GCP_RESOURCE_NAME,
@@ -159,6 +160,7 @@ class SpanData {
159160

160161
describe.skipEnterprise('Tracing Tests', () => {
161162
let firestore: Firestore;
163+
let randomCol: CollectionReference;
162164
let tracerProvider: NodeTracerProvider;
163165
let inMemorySpanExporter: InMemorySpanExporter;
164166
let consoleSpanExporter: ConsoleSpanExporter;
@@ -299,6 +301,7 @@ describe.skipEnterprise('Tracing Tests', () => {
299301
}
300302

301303
firestore = new Firestore(settings);
304+
randomCol = firestore.collection('node_tracing_' + autoId());
302305
}
303306

304307
function getSettingsAttributes(): Attributes {
@@ -768,7 +771,7 @@ describe.skipEnterprise('Tracing Tests', () => {
768771
function runTestCases() {
769772
it('document reference get()', async () => {
770773
await runFirestoreOperationInRootSpan(() =>
771-
firestore.collection('foo').doc('bar').get(),
774+
randomCol.doc('bar').get(),
772775
);
773776
await waitForCompletedSpans(3);
774777
expectSpanHierarchy(
@@ -789,7 +792,7 @@ describe.skipEnterprise('Tracing Tests', () => {
789792

790793
it('document reference create()', async () => {
791794
await runFirestoreOperationInRootSpan(() =>
792-
firestore.collection('foo').doc().create({}),
795+
randomCol.doc().create({}),
793796
);
794797
await waitForCompletedSpans(3);
795798
expectSpanHierarchy(
@@ -805,7 +808,7 @@ describe.skipEnterprise('Tracing Tests', () => {
805808

806809
it('document reference delete()', async () => {
807810
await runFirestoreOperationInRootSpan(() =>
808-
firestore.collection('foo').doc('bar').delete(),
811+
randomCol.doc('bar').delete(),
809812
);
810813
await waitForCompletedSpans(3);
811814
expectSpanHierarchy(
@@ -821,7 +824,7 @@ describe.skipEnterprise('Tracing Tests', () => {
821824

822825
it('document reference set()', async () => {
823826
await runFirestoreOperationInRootSpan(() =>
824-
firestore.collection('foo').doc('bar').set({foo: 'bar'}),
827+
randomCol.doc('bar').set({foo: 'bar'}),
825828
);
826829
await waitForCompletedSpans(3);
827830
expectSpanHierarchy(
@@ -838,10 +841,10 @@ describe.skipEnterprise('Tracing Tests', () => {
838841
it('document reference update()', async () => {
839842
// Make sure the document exists before updating it.
840843
// Perform the `set` operation outside of the root span.
841-
await firestore.collection('foo').doc('bar').set({foo: 'bar'});
844+
await randomCol.doc('bar').set({foo: 'bar'});
842845

843846
await runFirestoreOperationInRootSpan(() =>
844-
firestore.collection('foo').doc('bar').update('foo', 'bar2'),
847+
randomCol.doc('bar').update('foo', 'bar2'),
845848
);
846849
await waitForCompletedSpans(3);
847850
expectSpanHierarchy(
@@ -857,7 +860,7 @@ describe.skipEnterprise('Tracing Tests', () => {
857860

858861
it('document reference list collections', async () => {
859862
await runFirestoreOperationInRootSpan(() =>
860-
firestore.collection('foo').doc('bar').listCollections(),
863+
randomCol.doc('bar').listCollections(),
861864
);
862865
await waitForCompletedSpans(2);
863866
expectSpanHierarchy(
@@ -872,7 +875,7 @@ describe.skipEnterprise('Tracing Tests', () => {
872875

873876
it('aggregate query get()', async () => {
874877
await runFirestoreOperationInRootSpan(() =>
875-
firestore.collection('foo').count().get(),
878+
randomCol.count().get(),
876879
);
877880
await waitForCompletedSpans(2);
878881
expectSpanHierarchy(SPAN_NAME_TEST_ROOT, SPAN_NAME_AGGREGATION_QUERY_GET);
@@ -885,7 +888,7 @@ describe.skipEnterprise('Tracing Tests', () => {
885888

886889
it('collection reference add()', async () => {
887890
await runFirestoreOperationInRootSpan(() =>
888-
firestore.collection('foo').add({foo: 'bar'}),
891+
randomCol.add({foo: 'bar'}),
889892
);
890893
await waitForCompletedSpans(4);
891894
expectSpanHierarchy(
@@ -903,7 +906,7 @@ describe.skipEnterprise('Tracing Tests', () => {
903906
// Enterprise: field mask is not supported
904907
it.skipEnterprise('collection reference list documents', async () => {
905908
await runFirestoreOperationInRootSpan(() =>
906-
firestore.collection('foo').listDocuments(),
909+
randomCol.listDocuments(),
907910
);
908911
await waitForCompletedSpans(2);
909912
expectSpanHierarchy(
@@ -918,7 +921,7 @@ describe.skipEnterprise('Tracing Tests', () => {
918921

919922
it('query get()', async () => {
920923
await runFirestoreOperationInRootSpan(() =>
921-
firestore.collection('foo').where('foo', '==', 'bar').limit(1).get(),
924+
randomCol.where('foo', '==', 'bar').limit(1).get(),
922925
);
923926
await waitForCompletedSpans(2);
924927
expectSpanHierarchy(SPAN_NAME_TEST_ROOT, SPAN_NAME_QUERY_GET);
@@ -935,8 +938,8 @@ describe.skipEnterprise('Tracing Tests', () => {
935938
});
936939

937940
it('firestore getAll()', async () => {
938-
const docRef1 = firestore.collection('foo').doc('1');
939-
const docRef2 = firestore.collection('foo').doc('2');
941+
const docRef1 = randomCol.doc('1');
942+
const docRef2 = randomCol.doc('2');
940943
await runFirestoreOperationInRootSpan(() =>
941944
firestore.getAll(docRef1, docRef2),
942945
);
@@ -954,16 +957,16 @@ describe.skipEnterprise('Tracing Tests', () => {
954957
});
955958

956959
it('transaction', async () => {
957-
const docRef1 = firestore.collection('foo').doc('bar');
958-
const docRef2 = firestore.collection('foo').doc('bar');
960+
const docRef1 = randomCol.doc('bar');
961+
const docRef2 = randomCol.doc('bar');
959962

960963
await runFirestoreOperationInRootSpan(async () => {
961964
return firestore.runTransaction(async transaction => {
962965
await transaction.get(docRef1);
963966
await transaction.getAll(docRef1, docRef2);
964-
await transaction.get(firestore.collection('foo').limit(1));
965-
await transaction.get(firestore.collection('nonexistent').count());
966-
transaction.set(firestore.collection('foo').doc(), {foo: 'bar'});
967+
await transaction.get(randomCol.limit(1));
968+
await transaction.get(firestore.collection('nonexistent_' + autoId()).count());
969+
transaction.set(randomCol.doc(), {foo: 'bar'});
967970
});
968971
});
969972

@@ -1032,7 +1035,7 @@ describe.skipEnterprise('Tracing Tests', () => {
10321035
// Service not implemented for Enterprise DB: PartitionQuery
10331036
it.skipEnterprise('partition query', async () => {
10341037
await runFirestoreOperationInRootSpan(async () => {
1035-
const query = firestore.collectionGroup('foo');
1038+
const query = firestore.collectionGroup('node_cg_' + autoId());
10361039
let numPartitions = 0;
10371040
// eslint-disable-next-line @typescript-eslint/no-unused-vars
10381041
for await (const partition of query.getPartitions(3)) {
@@ -1052,11 +1055,11 @@ describe.skipEnterprise('Tracing Tests', () => {
10521055
await runFirestoreOperationInRootSpan(async () => {
10531056
const bulkWriter = firestore.bulkWriter();
10541057
// No need to await the set operations as 'close()' will commit all writes before closing.
1055-
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 1});
1056-
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 2});
1057-
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 3});
1058-
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 4});
1059-
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 5});
1058+
void bulkWriter.set(randomCol.doc(), {foo: 1});
1059+
void bulkWriter.set(randomCol.doc(), {foo: 2});
1060+
void bulkWriter.set(randomCol.doc(), {foo: 3});
1061+
void bulkWriter.set(randomCol.doc(), {foo: 4});
1062+
void bulkWriter.set(randomCol.doc(), {foo: 5});
10601063
await bulkWriter.close();
10611064
});
10621065

handwritten/firestore/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"system-test:named-db:emulator:rest": "FIRESTORE_NAMED_DATABASE=test-db 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",
4949
"system-test:named-db:emulator:grpc": "FIRESTORE_NAMED_DATABASE=test-db FIRESTORE_EMULATOR_HOST=localhost:8080 mocha build/system-test --timeout 1200000",
50-
"system-test": "npm run system-test:grpc && npm run system-test:rest && npm run system-test:named-db:grpc && npm run system-test:named-db:rest",
50+
"system-test": "concurrently -p \"[{name}]\" -n \"grpc,rest,named-db-grpc,named-db-rest\" -c \"cyan,magenta,blue,yellow\" \"npm:system-test:grpc\" \"npm:system-test:rest\" \"npm:system-test:named-db:grpc\" \"npm:system-test:named-db:rest\"",
5151
"system-test:nightly": "FIRESTORE_TARGET_BACKEND=nightly FIRESTORE_NAMED_DATABASE=enterprise RUN_ENTERPRISE_TESTS=yes GCLOUD_PROJECT=firestore-sdk-nightly mocha build/system-test --timeout 1200000",
52-
"system-test:emulator": "npm run system-test:emulator:grpc && npm run system-test:emulator:rest && npm run system-test:named-db:emulator:grpc && npm run system-test:named-db:emulator:rest",
52+
"system-test:emulator": "concurrently -p \"[{name}]\" -n \"grpc,rest,named-db-grpc,named-db-rest\" -c \"cyan,magenta,blue,yellow\" \"npm:system-test:emulator:grpc\" \"npm:system-test:emulator:rest\" \"npm:system-test:named-db:emulator:grpc\" \"npm:system-test:named-db:emulator:rest\"",
5353
"presystem-test": "npm run compile",
5454
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../",
5555
"conformance": "mocha build/conformance",
@@ -96,6 +96,7 @@
9696
"chai": "^4.5.0",
9797
"chai-as-promised": "^7.1.2",
9898
"codecov": "^3.8.3",
99+
"concurrently": "^9.1.2",
99100
"duplexify": "^4.1.3",
100101
"eslint-plugin-node": "^11.1.0",
101102
"execa": "^9.6.0",

0 commit comments

Comments
 (0)