Skip to content

Commit 4330039

Browse files
Spec test fixes (#1081)
1 parent fbcfeef commit 4330039

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

packages/firestore/test/unit/specs/spec_builder.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ import {
4646
SpecQueryFilter,
4747
SpecQueryOrderBy,
4848
SpecStep,
49-
SpecWatchFilter
49+
SpecWatchFilter,
50+
SpecWriteAck,
51+
SpecWriteFailure
5052
} from './spec_test_runner';
5153
import { TimerId } from '../../../src/util/async_queue';
5254

@@ -464,7 +466,7 @@ export class SpecBuilder {
464466
/**
465467
* Acks a write with a version and optional additional options.
466468
*
467-
* expectUserCallback defaults to true if options are omitted.
469+
* expectUserCallback defaults to true if omitted.
468470
*/
469471
writeAcks(
470472
doc: string,
@@ -474,11 +476,13 @@ export class SpecBuilder {
474476
this.nextStep();
475477
options = options || {};
476478

477-
this.currentStep = {
478-
writeAck: { version, keepInQueue: !!options.keepInQueue }
479-
};
479+
const writeAck: SpecWriteAck = { version };
480+
if (options.keepInQueue) {
481+
writeAck.keepInQueue = true;
482+
}
483+
this.currentStep = { writeAck };
480484

481-
if (options.expectUserCallback) {
485+
if (options.expectUserCallback !== false) {
482486
return this.expectUserCallbacks({ acknowledged: [doc] });
483487
} else {
484488
return this;
@@ -488,7 +492,7 @@ export class SpecBuilder {
488492
/**
489493
* Fails a write with an error and optional additional options.
490494
*
491-
* expectUserCallback defaults to true if options are omitted.
495+
* expectUserCallback defaults to true if omitted.
492496
*/
493497
failWrite(
494498
doc: string,
@@ -506,9 +510,13 @@ export class SpecBuilder {
506510
? options.keepInQueue
507511
: !isPermanentFailure;
508512

509-
this.currentStep = { failWrite: { error, keepInQueue } };
513+
const failWrite: SpecWriteFailure = { error };
514+
if (keepInQueue) {
515+
failWrite.keepInQueue = true;
516+
}
517+
this.currentStep = { failWrite };
510518

511-
if (options.expectUserCallback) {
519+
if (options.expectUserCallback !== false) {
512520
return this.expectUserCallbacks({ rejected: [doc] });
513521
} else {
514522
return this;

packages/firestore/test/unit/specs/spec_test_runner.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,18 @@ abstract class TestRunner {
947947
if ('isPrimary' in expectation) {
948948
expect(this.isPrimaryClient).to.eq(expectation.isPrimary!, 'isPrimary');
949949
}
950-
if ('userCallbacks' in expectation) {
951-
expect(this.acknowledgedDocs).to.have.members(
952-
expectation.userCallbacks.acknowledgedDocs
953-
);
954-
expect(this.rejectedDocs).to.have.members(
955-
expectation.userCallbacks.rejectedDocs
956-
);
957-
}
950+
}
951+
952+
if (expectation && expectation.userCallbacks) {
953+
expect(this.acknowledgedDocs).to.have.members(
954+
expectation.userCallbacks.acknowledgedDocs
955+
);
956+
expect(this.rejectedDocs).to.have.members(
957+
expectation.userCallbacks.rejectedDocs
958+
);
959+
} else {
960+
expect(this.acknowledgedDocs).to.be.empty;
961+
expect(this.rejectedDocs).to.be.empty;
958962
}
959963

960964
if (this.numClients === 1) {
@@ -1393,9 +1397,11 @@ export type SpecWriteAck = {
13931397
* Whether we should keep the write in our internal queue. This should only
13941398
* be set to 'true' if the client ignores the write (e.g. a secondary client
13951399
* which ignores write acknowledgments).
1400+
*
1401+
* Defaults to false.
13961402
*/
13971403
// PORTING NOTE: Multi-Tab only.
1398-
keepInQueue: boolean;
1404+
keepInQueue?: boolean;
13991405
};
14001406

14011407
export type SpecWriteFailure = {
@@ -1405,8 +1411,10 @@ export type SpecWriteFailure = {
14051411
* Whether we should keep the write in our internal queue. This should be set
14061412
* to 'true' for transient errors or if the client ignores the failure
14071413
* (e.g. a secondary client which ignores write rejections).
1414+
*
1415+
* Defaults to false.
14081416
*/
1409-
keepInQueue: boolean;
1417+
keepInQueue?: boolean;
14101418
};
14111419

14121420
export interface SpecWatchEntity {

packages/firestore/test/unit/specs/write_spec.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ describeSpec('Writes:', [], () => {
645645
expectRequestCount({ handshakes: 2, writes: 2, closes: 1 })
646646
)
647647
.expectNumOutstandingWrites(1)
648-
.writeAcks('collection/key', 1, { expectUserCallback: false })
648+
.writeAcks('collection/key', 1)
649649
.expectNumOutstandingWrites(0);
650650
});
651651

0 commit comments

Comments
 (0)