Skip to content

Commit f037570

Browse files
Floating promise lint error fixes (#2400)
* I will fix the floating promise errors. This PR fixes all the floating promise errors in the test files. It also converts all the `then` calls to `async/await` in the test files. * remove jules txt output files * Fix hanging promise errors * Attempting CI fix of tests * Change solution to floating promises where adding await previously changed the meaning of the test. * revert void assert.rejects changes in gapic_firestore_v1beta1.ts tests * Address PR comments --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent bc11ab8 commit f037570

File tree

13 files changed

+1816
-2182
lines changed

13 files changed

+1816
-2182
lines changed

dev/system-test/firestore.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,12 @@ describe('Firestore class', () => {
552552
expect(docs[1].data()!.toString()).to.deep.equal('post2, by author2');
553553
});
554554

555-
it('cannot make calls after the client has been terminated', () => {
555+
it('cannot make calls after the client has been terminated', async () => {
556556
const ref1 = randomCol.doc('doc1');
557-
return firestore
558-
.terminate()
559-
.then(() => {
560-
return ref1.set({foo: 100});
561-
})
562-
.then(() => Promise.reject('set() should have failed'))
563-
.catch(err => {
564-
expect(err.message).to.equal('The client has already been terminated');
565-
});
557+
await firestore.terminate();
558+
return expect(ref1.set({foo: 100})).to.eventually.be.rejectedWith(
559+
'The client has already been terminated',
560+
);
566561
});
567562

568563
it('throws an error if terminate() is called with active listeners', async () => {
@@ -582,7 +577,7 @@ describe('Firestore class', () => {
582577
it('throws an error if terminate() is called with pending BulkWriter operations', async () => {
583578
const writer = firestore.bulkWriter();
584579
const ref = randomCol.doc('doc-1');
585-
writer.set(ref, {foo: 'bar'});
580+
void writer.set(ref, {foo: 'bar'});
586581
await expect(firestore.terminate()).to.eventually.be.rejectedWith(
587582
'All onSnapshot() listeners must be unsubscribed, and all BulkWriter ' +
588583
'instances must be closed before terminating the client. There are 0 ' +
@@ -1217,7 +1212,7 @@ describe('DocumentReference class', () => {
12171212
});
12181213

12191214
// tslint:disable-next-line:only-arrow-function
1220-
it('can add and delete fields sequentially', function () {
1215+
it('can add and delete fields sequentially', async function () {
12211216
this.timeout(30 * 1000);
12221217

12231218
const ref = randomCol.doc('doc');
@@ -1287,7 +1282,7 @@ describe('DocumentReference class', () => {
12871282
});
12881283
}
12891284

1290-
return promise;
1285+
await promise;
12911286
});
12921287

12931288
// tslint:disable-next-line:only-arrow-function
@@ -1555,7 +1550,7 @@ describe('DocumentReference class', () => {
15551550
() => {
15561551
unsubscribe1();
15571552
unsubscribe2();
1558-
Promise.all(promises).then(() => done());
1553+
void Promise.all(promises).then(() => done());
15591554
},
15601555
];
15611556

@@ -1595,7 +1590,7 @@ describe('DocumentReference class', () => {
15951590
() => {
15961591
unsubscribe1();
15971592
unsubscribe2();
1598-
Promise.all(promises).then(() => done());
1593+
void Promise.all(promises).then(() => done());
15991594
},
16001595
];
16011596

@@ -3161,7 +3156,7 @@ describe('Query class', () => {
31613156
const ref1 = randomCol.doc('doc1');
31623157
const ref2 = randomCol.doc('doc2');
31633158

3164-
Promise.all([ref1.set({foo: 'a'}), ref2.set({foo: 'b'})]).then(() => {
3159+
void Promise.all([ref1.set({foo: 'a'}), ref2.set({foo: 'b'})]).then(() => {
31653160
return randomCol
31663161
.stream()
31673162
.on('data', d => {
@@ -5208,7 +5203,7 @@ describe('Aggregation queries', () => {
52085203
});
52095204

52105205
it("terminate doesn't crash when there is aggregate query in flight", async () => {
5211-
col.aggregate({count: AggregateField.count()}).get();
5206+
void col.aggregate({count: AggregateField.count()}).get();
52125207
await firestore.terminate();
52135208
});
52145209

@@ -7048,12 +7043,12 @@ describe('WriteBatch class', () => {
70487043
});
70497044
});
70507045

7051-
it('has a full stack trace if set() errors', () => {
7046+
it('has a full stack trace if set() errors', async () => {
70527047
// Use an invalid document name that the backend will reject.
70537048
const ref = randomCol.doc('__doc__');
70547049
const batch = firestore.batch();
70557050
batch.set(ref, {foo: 'a'});
7056-
return batch
7051+
await batch
70577052
.commit()
70587053
.then(() => Promise.reject('commit() should have failed'))
70597054
.catch((err: Error) => {
@@ -7265,7 +7260,7 @@ describe('BulkWriter class', () => {
72657260

72667261
it('can terminate once BulkWriter is closed', async () => {
72677262
const ref = randomCol.doc('doc1');
7268-
writer.set(ref, {foo: 'bar'});
7263+
void writer.set(ref, {foo: 'bar'});
72697264
await writer.close();
72707265
return firestore.terminate();
72717266
});

dev/system-test/tracing.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -980,11 +980,11 @@ describe('Tracing Tests', () => {
980980
await runFirestoreOperationInRootSpan(async () => {
981981
const bulkWriter = firestore.bulkWriter();
982982
// No need to await the set operations as 'close()' will commit all writes before closing.
983-
bulkWriter.set(firestore.collection('foo').doc(), {foo: 1});
984-
bulkWriter.set(firestore.collection('foo').doc(), {foo: 2});
985-
bulkWriter.set(firestore.collection('foo').doc(), {foo: 3});
986-
bulkWriter.set(firestore.collection('foo').doc(), {foo: 4});
987-
bulkWriter.set(firestore.collection('foo').doc(), {foo: 5});
983+
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 1});
984+
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 2});
985+
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 3});
986+
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 4});
987+
void bulkWriter.set(firestore.collection('foo').doc(), {foo: 5});
988988
await bulkWriter.close();
989989
});
990990

dev/test/backoff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('ExponentialBackoff', () => {
166166
// The timeout handler for this test simply idles forever.
167167
setTimeoutHandler(() => {});
168168

169-
backoff.backoffAndWait().then(nop);
169+
void backoff.backoffAndWait().then(nop);
170170
await expect(backoff.backoffAndWait()).to.eventually.be.rejectedWith(
171171
'A backoff operation is already in progress.',
172172
);

0 commit comments

Comments
 (0)