Skip to content

Adding experimentalAutoDetectLongPolling #3724

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 33 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
33d69f3
Upgrade to latest version of closure
rafikhan Jul 8, 2020
35d4713
Adding changeset
rafikhan Jul 8, 2020
d24a58f
Updating changeset message
rafikhan Jul 8, 2020
6084312
Fixing stylization in changeset copy
rafikhan Jul 8, 2020
a2a8817
Merge branch 'master' into khanrafi/webchannelupgrade
rafikhan Jul 9, 2020
433c8ba
Merge branch 'master' into khanrafi/webchannelupgrade
rafikhan Jul 10, 2020
4f544d8
WIP
rafikhan Jul 31, 2020
e778894
Merge branch 'master' into khanrafi/webchannelupgrade
rafikhan Jul 31, 2020
cffed37
Merge branch 'master' of github.com:firebase/firebase-js-sdk into kha…
rafikhan Sep 1, 2020
bb5fe2c
Updating to match new patterns
rafikhan Sep 1, 2020
59c8900
Making member names match conventions on others
rafikhan Sep 1, 2020
dbffc65
Making the linter happy
rafikhan Sep 1, 2020
bee717c
Fixing bug caught by unit tests and misc polish
rafikhan Sep 1, 2020
7356673
Turning auto detection on by default
rafikhan Sep 1, 2020
14887c4
Turning auto detection on by default
rafikhan Sep 1, 2020
66ed0bf
Merge branch 'khanrafi/webchannelupgrade' of github.com:firebase/fire…
rafikhan Sep 1, 2020
fb6a370
Update packages/firestore/src/util/input_validation.ts
rafikhan Sep 8, 2020
458c75a
Update packages/firebase/index.d.ts
rafikhan Sep 9, 2020
ecd8469
Changing default to false
rafikhan Sep 9, 2020
3c34f6d
Fixing grammar
rafikhan Sep 9, 2020
c26a7ec
Merge branch 'master' into khanrafi/webchannelupgrade
rafikhan Sep 22, 2020
f9859a9
Adding integration test
rafikhan Sep 29, 2020
1d8d8c3
Undoing formatting changes
rafikhan Sep 29, 2020
5222ae7
Resetting hard code to false
rafikhan Sep 29, 2020
9f756ad
Update packages/firestore/src/core/database_info.ts
rafikhan Sep 29, 2020
94095b7
Update packages/firestore/test/integration/api/database.test.ts
rafikhan Sep 29, 2020
500b3d9
Create yellow-turkeys-lay.md
rafikhan Sep 29, 2020
2eeffd2
Update .changeset/yellow-turkeys-lay.md
rafikhan Sep 30, 2020
490c0ef
Update .changeset/yellow-turkeys-lay.md
rafikhan Sep 30, 2020
ed94332
Update index.d.ts
rafikhan Oct 6, 2020
1b10fb5
Update yellow-turkeys-lay.md
rafikhan Oct 6, 2020
64fa5fb
Merge branch 'master' of github.com:firebase/firebase-js-sdk into kha…
rafikhan Oct 7, 2020
c972e4c
Updating unit test to contain proper error string
rafikhan Oct 8, 2020
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
11 changes: 11 additions & 0 deletions .changeset/yellow-turkeys-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"firebase": patch
"@firebase/firestore-types": patch
"@firebase/firestore": patch
"@firebase/webchannel-wrapper": patch
---

Adding experimentalAutoDetectLongPolling to FirestoreSettings. It configures the SDK's
underlying transport (WebChannel) to automatically detect if long-polling should be used.
This is very similar to `experimentalForceLongPolling`, but only uses long-polling if
required.
20 changes: 16 additions & 4 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7879,15 +7879,27 @@ declare namespace firebase.firestore {
* buffer traffic indefinitely. Use of this option will cause some
* performance degradation though.
*
* This setting may be removed in a future release. If you find yourself
* using it to work around a specific network reliability issue, please
* tell us about it in
* https://github.com/firebase/firebase-js-sdk/issues/1674.
* This setting cannot be used with experimentalAutoDetectLongPolling and
* may be removed in a future release. If you find yourself using it to
* work around a specific network reliability issue, please tell us about
* it in https://github.com/firebase/firebase-js-sdk/issues/1674.
*
* @webonly
*/
experimentalForceLongPolling?: boolean;

/**
* Configures the SDK's underlying transport (WebChannel) to automatically detect if
* long-polling should be used. This is very similar to `experimentalForceLongPolling`,
* but only uses long-polling if required.
*
* This setting will likely be enabled by default in future releases and cannot be
* combined with `experimentalForceLongPolling`.
*
* @webonly
*/
experimentalAutoDetectLongPolling?: boolean;

/**
* Whether to skip nested properties that are set to `undefined` during
* object serialization. If set to `true`, these properties are skipped
Expand Down
1 change: 1 addition & 0 deletions packages/firestore-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Settings {
timestampsInSnapshots?: boolean;
cacheSizeBytes?: number;
experimentalForceLongPolling?: boolean;
experimentalAutoDetectLongPolling?: boolean;
ignoreUndefinedProperties?: boolean;
merge?: boolean;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/exp/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class FirebaseFirestore
this._persistenceKey,
settings.host ?? DEFAULT_HOST,
settings.ssl ?? DEFAULT_SSL,
/* forceLongPolling= */ false
/* forceLongPolling= */ false,
/* forceAutoDetectLongPolling= */ true
);
return {
asyncQueue: this._queue,
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/lite/src/api/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function getDatastore(firestore: FirebaseFirestore): Datastore {
firestore._persistenceKey,
settings.host ?? DEFAULT_HOST,
settings.ssl ?? DEFAULT_SSL,
/* forceLongPolling= */ false
/* forceLongPolling= */ false,
/* forceAutoDetectLongPolling= */ true
);

const connection = newConnection(databaseInfo);
Expand Down
29 changes: 27 additions & 2 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ import {
validateOptionNames,
validatePositiveNumber,
validateStringEnum,
valueDescription
valueDescription,
validateIsNotUsedTogether
} from '../util/input_validation';
import { getLogLevel, logError, LogLevel, setLogLevel } from '../util/log';
import { AutoId } from '../util/misc';
Expand Down Expand Up @@ -146,6 +147,7 @@ const DEFAULT_HOST = 'firestore.googleapis.com';
const DEFAULT_SSL = true;
const DEFAULT_TIMESTAMPS_IN_SNAPSHOTS = true;
const DEFAULT_FORCE_LONG_POLLING = false;
const DEFAULT_FORCE_AUTO_DETECT_LONG_POLLING = false;
const DEFAULT_IGNORE_UNDEFINED_PROPERTIES = false;

/**
Expand Down Expand Up @@ -191,6 +193,8 @@ class FirestoreSettings {

readonly experimentalForceLongPolling: boolean;

readonly experimentalAutoDetectLongPolling: boolean;

readonly ignoreUndefinedProperties: boolean;

// Can be a google-auth-library or gapi client.
Expand Down Expand Up @@ -221,6 +225,7 @@ class FirestoreSettings {
'timestampsInSnapshots',
'cacheSizeBytes',
'experimentalForceLongPolling',
'experimentalAutoDetectLongPolling',
'ignoreUndefinedProperties'
]);

Expand Down Expand Up @@ -294,6 +299,23 @@ class FirestoreSettings {
);
this.experimentalForceLongPolling =
settings.experimentalForceLongPolling ?? DEFAULT_FORCE_LONG_POLLING;

validateNamedOptionalType(
'settings',
'boolean',
'experimentalAutoDetectLongPolling',
settings.experimentalAutoDetectLongPolling
);
this.experimentalAutoDetectLongPolling =
settings.experimentalAutoDetectLongPolling ??
DEFAULT_FORCE_AUTO_DETECT_LONG_POLLING;

validateIsNotUsedTogether(
'experimentalForceLongPolling',
settings.experimentalForceLongPolling,
'experimentalAutoDetectLongPolling',
settings.experimentalAutoDetectLongPolling
);
}

isEqual(other: FirestoreSettings): boolean {
Expand All @@ -305,6 +327,8 @@ class FirestoreSettings {
this.cacheSizeBytes === other.cacheSizeBytes &&
this.experimentalForceLongPolling ===
other.experimentalForceLongPolling &&
this.experimentalAutoDetectLongPolling ===
other.experimentalAutoDetectLongPolling &&
this.ignoreUndefinedProperties === other.ignoreUndefinedProperties
);
}
Expand Down Expand Up @@ -552,7 +576,8 @@ export class Firestore implements PublicFirestore, FirebaseService {
this._persistenceKey,
this._settings.host,
this._settings.ssl,
this._settings.experimentalForceLongPolling
this._settings.experimentalForceLongPolling,
this._settings.experimentalAutoDetectLongPolling
);
}

Expand Down
5 changes: 4 additions & 1 deletion packages/firestore/src/core/database_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ export class DatabaseInfo {
* @param ssl Whether to use SSL when connecting.
* @param forceLongPolling Whether to use the forceLongPolling option
* when using WebChannel as the network transport.
* @param autoDetectLongPolling Whether to use the detectBufferingProxy
* option when using WebChannel as the network transport.
*/
constructor(
readonly databaseId: DatabaseId,
readonly persistenceKey: string,
readonly host: string,
readonly ssl: boolean,
readonly forceLongPolling: boolean
readonly forceLongPolling: boolean,
readonly autoDetectLongPolling: boolean
) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ const XHR_TIMEOUT_SECS = 15;

export class WebChannelConnection extends RestConnection {
private readonly forceLongPolling: boolean;
private readonly autoDetectLongPolling: boolean;

constructor(info: DatabaseInfo) {
super(info);
this.forceLongPolling = info.forceLongPolling;
this.autoDetectLongPolling = info.autoDetectLongPolling;
}

protected performRPCRequest<Req, Resp>(
Expand Down Expand Up @@ -183,7 +185,8 @@ export class WebChannelConnection extends RestConnection {
// timeouts to kick in if the request isn't working.
forwardChannelRequestTimeoutMs: 10 * 60 * 1000
},
forceLongPolling: this.forceLongPolling
forceLongPolling: this.forceLongPolling,
detectBufferingProxy: this.autoDetectLongPolling
};

this.modifyHeadersForRequest(request.initMessageHeaders!, token);
Expand Down
17 changes: 17 additions & 0 deletions packages/firestore/src/util/input_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ export function validateNamedOptionalType(
}
}

/**
* Validates that two boolean options are not set at the same time.
*/
export function validateIsNotUsedTogether(
optionName1: string,
argument1: boolean | undefined,
optionName2: string,
argument2: boolean | undefined
): void {
if (argument1 === true && argument2 === true) {
throw new FirestoreError(
Code.INVALID_ARGUMENT,
`${optionName1} and ${optionName2} cannot be used together.`
);
}
}

export function validateArrayElements<T>(
functionName: string,
optionName: string,
Expand Down
29 changes: 28 additions & 1 deletion packages/firestore/test/integration/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import * as firebaseExport from '../util/firebase_export';
import {
apiDescribe,
withTestCollection,
withTestDbsSettings,
withTestDb,
withTestDbs,
withTestDoc,
withTestDocAndInitialData
} from '../util/helpers';
import { DEFAULT_SETTINGS } from '../util/settings';
import { DEFAULT_SETTINGS, DEFAULT_PROJECT_ID } from '../util/settings';

use(chaiAsPromised);

Expand Down Expand Up @@ -1600,4 +1601,30 @@ apiDescribe('Database', (persistence: boolean) => {
});
});
});

it('can set and get data with auto detect long polling enabled', () => {
const settings = {
...DEFAULT_SETTINGS,
experimentalAutoDetectLongPolling: true
};

return withTestDbsSettings(
persistence,
DEFAULT_PROJECT_ID,
settings,
1,
async ([db]) => {
const data = { name: 'Rafi', email: '[email protected]' };
const doc = await db.collection('users').doc();

return doc
.set(data)
.then(() => doc.get())
.then(snapshot => {
expect(snapshot.exists).to.be.ok;
expect(snapshot.data()).to.deep.equal(data);
});
}
);
});
});
3 changes: 2 additions & 1 deletion packages/firestore/test/integration/util/internal_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export function getDefaultDatabaseInfo(): DatabaseInfo {
'persistenceKey',
DEFAULT_SETTINGS.host!,
!!DEFAULT_SETTINGS.ssl,
!!DEFAULT_SETTINGS.experimentalForceLongPolling
!!DEFAULT_SETTINGS.experimentalForceLongPolling,
!!DEFAULT_SETTINGS.experimentalAutoDetectLongPolling
);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/firestore/test/unit/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ describe('Settings', () => {
);
});

it('can not use mutually exclusive settings together', () => {
// Use a new instance of Firestore in order to configure settings.
const firestoreClient = newTestFirestore();
expect(
firestoreClient.settings.bind(firestoreClient.settings, {
experimentalForceLongPolling: true,
experimentalAutoDetectLongPolling: true
})
).to.throw(`can not be used together.`);
});

it('can merge settings', () => {
// Use a new instance of Firestore in order to configure settings.
const firestoreClient = newTestFirestore();
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/test/unit/remote/rest_connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ describe('RestConnection', () => {
'persistenceKey',
'example.com',
/*ssl=*/ false,
/*forceLongPolling=*/ false
/*forceLongPolling=*/ false,
/*autoDetectLongPolling=*/ false
);
const connection = new TestRestConnection(testDatabaseInfo);

Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/test/unit/specs/spec_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ abstract class TestRunner {
TEST_PERSISTENCE_KEY,
'host',
/*ssl=*/ false,
/*forceLongPolling=*/ false
/*forceLongPolling=*/ false,
/*autoDetectLongPolling=*/ false
);

// TODO(mrschmidt): During client startup in `firestore_client`, we block
Expand Down
1 change: 1 addition & 0 deletions packages/webchannel-wrapper/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface WebChannelOptions {
httpSessionIdParam?: string;
httpHeadersOverwriteParam?: string;
forceLongPolling?: boolean;
detectBufferingProxy?: boolean;
fastHandshake?: boolean;
disableRedac?: boolean;
clientProfile?: string;
Expand Down