Skip to content

Adding back callback assert #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
26 changes: 17 additions & 9 deletions packages/firestore/test/unit/specs/spec_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import {
SpecQueryFilter,
SpecQueryOrderBy,
SpecStep,
SpecWatchFilter
SpecWatchFilter,
SpecWriteAck,
SpecWriteFailure
} from './spec_test_runner';
import { TimerId } from '../../../src/util/async_queue';

Expand Down Expand Up @@ -464,7 +466,7 @@ export class SpecBuilder {
/**
* Acks a write with a version and optional additional options.
*
* expectUserCallback defaults to true if options are omitted.
* expectUserCallback defaults to true if omitted.
*/
writeAcks(
doc: string,
Expand All @@ -474,11 +476,13 @@ export class SpecBuilder {
this.nextStep();
options = options || {};

this.currentStep = {
writeAck: { version, keepInQueue: !!options.keepInQueue }
};
const writeAck: SpecWriteAck = { version };
if (options.keepInQueue) {
writeAck.keepInQueue = true;
}
this.currentStep = { writeAck };

if (options.expectUserCallback) {
if (options.expectUserCallback !== false) {
return this.expectUserCallbacks({ acknowledged: [doc] });
} else {
return this;
Expand All @@ -488,7 +492,7 @@ export class SpecBuilder {
/**
* Fails a write with an error and optional additional options.
*
* expectUserCallback defaults to true if options are omitted.
* expectUserCallback defaults to true if omitted.
*/
failWrite(
doc: string,
Expand All @@ -506,9 +510,13 @@ export class SpecBuilder {
? options.keepInQueue
: !isPermanentFailure;

this.currentStep = { failWrite: { error, keepInQueue } };
const failWrite: SpecWriteFailure = { error };
if (keepInQueue) {
failWrite.keepInQueue = true;
}
this.currentStep = { failWrite };

if (options.expectUserCallback) {
if (options.expectUserCallback !== false) {
return this.expectUserCallbacks({ rejected: [doc] });
} else {
return this;
Expand Down
28 changes: 18 additions & 10 deletions packages/firestore/test/unit/specs/spec_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,18 @@ abstract class TestRunner {
if ('isPrimary' in expectation) {
expect(this.isPrimaryClient).to.eq(expectation.isPrimary!, 'isPrimary');
}
if ('userCallbacks' in expectation) {
expect(this.acknowledgedDocs).to.have.members(
expectation.userCallbacks.acknowledgedDocs
);
expect(this.rejectedDocs).to.have.members(
expectation.userCallbacks.rejectedDocs
);
}
}

if (expectation && expectation.userCallbacks) {
expect(this.acknowledgedDocs).to.have.members(
expectation.userCallbacks.acknowledgedDocs
);
expect(this.rejectedDocs).to.have.members(
expectation.userCallbacks.rejectedDocs
);
} else {
expect(this.acknowledgedDocs).to.be.empty;
expect(this.rejectedDocs).to.be.empty;
}

if (this.numClients === 1) {
Expand Down Expand Up @@ -1393,9 +1397,11 @@ export type SpecWriteAck = {
* Whether we should keep the write in our internal queue. This should only
* be set to 'true' if the client ignores the write (e.g. a secondary client
* which ignores write acknowledgments).
*
* Defaults to false.
*/
// PORTING NOTE: Multi-Tab only.
keepInQueue: boolean;
keepInQueue?: boolean;
};

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

export interface SpecWatchEntity {
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/unit/specs/write_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ describeSpec('Writes:', [], () => {
expectRequestCount({ handshakes: 2, writes: 2, closes: 1 })
)
.expectNumOutstandingWrites(1)
.writeAcks('collection/key', 1, { expectUserCallback: false })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a bug before? Else I'm confused why this changed since the default is true, right? So omitting it is a change in behavior...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was wrong. Disabling and re-enabling the network should not affect whether we resolve the user callback. This now fails since I am asserting that I didn't get any unexpected write acknowledgments.

.writeAcks('collection/key', 1)
.expectNumOutstandingWrites(0);
});

Expand Down