Skip to content

Add timeout to OnlineState tracking. #412

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 12 commits into from
Mar 3, 2018
4 changes: 1 addition & 3 deletions packages/database/test/order_by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ describe('.orderBy tests', function() {
expect(addedPrevNames).to.deep.equal(expectedPrevNames);
});

it('Removing default listener removes non-default listener that loads all data', function(
done
) {
it('Removing default listener removes non-default listener that loads all data', function(done) {
const ref = getRandomNode() as Reference;

const initial = { key: 'value' };
Expand Down
28 changes: 7 additions & 21 deletions packages/database/test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1971,9 +1971,7 @@ describe('Query Tests', function() {
expect(val).to.equal(2);
});

it('.startAt() with two arguments works properly (case 1169).', function(
done
) {
it('.startAt() with two arguments works properly (case 1169).', function(done) {
const ref = getRandomNode() as Reference;
const data = {
Walker: {
Expand Down Expand Up @@ -2110,9 +2108,7 @@ describe('Query Tests', function() {
});
});

it(".endAt(null, 'f').limitToLast(5) returns the right set of children.", function(
done
) {
it(".endAt(null, 'f').limitToLast(5) returns the right set of children.", function(done) {
const ref = getRandomNode() as Reference;
ref.set(
{ a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', g: 'g', h: 'h' },
Expand All @@ -2134,9 +2130,7 @@ describe('Query Tests', function() {
);
});

it('complex update() at query root raises correct value event', function(
done
) {
it('complex update() at query root raises correct value event', function(done) {
const nodePair = getRandomNode(2);
const writer = nodePair[0];
const reader = nodePair[1];
Expand Down Expand Up @@ -2241,9 +2235,7 @@ describe('Query Tests', function() {
});
});

it('listen for child_added events with limit and different types fires properly', function(
done
) {
it('listen for child_added events with limit and different types fires properly', function(done) {
const nodePair = getRandomNode(2);
const writer = nodePair[0];
const reader = nodePair[1];
Expand Down Expand Up @@ -2285,9 +2277,7 @@ describe('Query Tests', function() {
});
});

it('listen for child_changed events with limit and different types fires properly', function(
done
) {
it('listen for child_changed events with limit and different types fires properly', function(done) {
const nodePair = getRandomNode(2);
const writer = nodePair[0];
const reader = nodePair[1];
Expand Down Expand Up @@ -2338,9 +2328,7 @@ describe('Query Tests', function() {
});
});

it('listen for child_remove events with limit and different types fires properly', function(
done
) {
it('listen for child_remove events with limit and different types fires properly', function(done) {
const nodePair = getRandomNode(2);
const writer = nodePair[0];
const reader = nodePair[1];
Expand Down Expand Up @@ -2442,9 +2430,7 @@ describe('Query Tests', function() {
);
});

it('listen for child_remove events when parent set to scalar', function(
done
) {
it('listen for child_remove events when parent set to scalar', function(done) {
const nodePair = getRandomNode(2);
const writer = nodePair[0];
const reader = nodePair[1];
Expand Down
48 changes: 12 additions & 36 deletions packages/database/test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ describe('Transaction Tests', function() {
});
});

it('Non-aborted transaction sets committed to true in callback.', function(
done
) {
it('Non-aborted transaction sets committed to true in callback.', function(done) {
const node = getRandomNode() as Reference;

node.transaction(
Expand All @@ -104,9 +102,7 @@ describe('Transaction Tests', function() {
);
});

it('Aborted transaction sets committed to false in callback.', function(
done
) {
it('Aborted transaction sets committed to false in callback.', function(done) {
const node = getRandomNode() as Reference;

node.transaction(
Expand Down Expand Up @@ -236,9 +232,7 @@ describe('Transaction Tests', function() {
return ea.promise;
});

it('Second transaction gets run immediately on previous output and only runs once.', function(
done
) {
it('Second transaction gets run immediately on previous output and only runs once.', function(done) {
const nodePair = getRandomNode(2) as Reference[];
let firstRun = false,
firstDone = false,
Expand Down Expand Up @@ -512,9 +506,7 @@ describe('Transaction Tests', function() {
);
});

it('Set should cancel already sent transactions that come back as datastale.', function(
done
) {
it('Set should cancel already sent transactions that come back as datastale.', function(done) {
const nodePair = getRandomNode(2) as Reference[];
let transactionCalls = 0;
nodePair[0].set(5, function() {
Expand Down Expand Up @@ -688,9 +680,7 @@ describe('Transaction Tests', function() {
return Promise.all([tx1, tx2]);
});

it('Doing set() in successful transaction callback works. Case 870.', function(
done
) {
it('Doing set() in successful transaction callback works. Case 870.', function(done) {
const node = getRandomNode() as Reference;
let transactionCalled = false;
let callbackCalled = false;
Expand All @@ -710,9 +700,7 @@ describe('Transaction Tests', function() {
);
});

it('Doing set() in aborted transaction callback works. Case 870.', function(
done
) {
it('Doing set() in aborted transaction callback works. Case 870.', function(done) {
const nodePair = getRandomNode(2) as Reference[],
node1 = nodePair[0],
node2 = nodePair[1];
Expand Down Expand Up @@ -1028,9 +1016,7 @@ describe('Transaction Tests', function() {
);
});

it('Transaction properly reverts data when you add a deeper listen.', function(
done
) {
it('Transaction properly reverts data when you add a deeper listen.', function(done) {
const refPair = getRandomNode(2) as Reference[],
ref1 = refPair[0],
ref2 = refPair[1];
Expand Down Expand Up @@ -1200,9 +1186,7 @@ describe('Transaction Tests', function() {
});
});

it("transaction() doesn't pick up cached data from previous once().", function(
done
) {
it("transaction() doesn't pick up cached data from previous once().", function(done) {
const refPair = getRandomNode(2) as Reference[];
const me = refPair[0],
other = refPair[1];
Expand All @@ -1229,9 +1213,7 @@ describe('Transaction Tests', function() {
});
});

it("transaction() doesn't pick up cached data from previous transaction.", function(
done
) {
it("transaction() doesn't pick up cached data from previous transaction.", function(done) {
const refPair = getRandomNode(2) as Reference[];
const me = refPair[0],
other = refPair[1];
Expand Down Expand Up @@ -1263,9 +1245,7 @@ describe('Transaction Tests', function() {
);
});

it('server values: local timestamp should eventually (but not immediately) match the server with txns', function(
done
) {
it('server values: local timestamp should eventually (but not immediately) match the server with txns', function(done) {
const refPair = getRandomNode(2) as Reference[],
writer = refPair[0],
reader = refPair[1],
Expand Down Expand Up @@ -1357,9 +1337,7 @@ describe('Transaction Tests', function() {
);
});

it("transaction() on queried location doesn't run initially on null (firebase-worker-queue depends on this).", function(
done
) {
it("transaction() on queried location doesn't run initially on null (firebase-worker-queue depends on this).", function(done) {
const ref = getRandomNode() as Reference;
ref.push({ a: 1, b: 2 }, function() {
ref
Expand Down Expand Up @@ -1437,9 +1415,7 @@ describe('Transaction Tests', function() {
);
});

it('transactions works with merges without the transaction path', function(
done
) {
it('transactions works with merges without the transaction path', function(done) {
const ref = getRandomNode() as Reference;

ref.update({ foo: 'bar' });
Expand Down
6 changes: 6 additions & 0 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Unreleased
- [changed] If the SDK's attempt to connect to the Cloud Firestore backend
neither succeeds nor fails within 10 seconds, the SDK will consider itself
"offline", causing get() calls to resolve with cached results, rather than
continuing to wait.

# 0.3.2
- [fixed] Fixed a regression in Firebase JS release 4.9.0 that could in certain
cases result in an "OnlineState should not affect limbo documents." assertion
crash when the client loses its network connection.
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/core/event_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ export class QueryListener {
return true;
}

// NOTE: We consider OnlineState.Unknown as online (it should become Failed
// NOTE: We consider OnlineState.Unknown as online (it should become Offline
// or Online if we wait long enough).
const maybeOnline = onlineState !== OnlineState.Failed;
const maybeOnline = onlineState !== OnlineState.Offline;
// Don't raise the event if we're online, aren't synced yet (checked
// above) and are waiting for a sync.
if (this.options.waitForSyncWhenOnline && maybeOnline) {
Expand All @@ -262,7 +262,7 @@ export class QueryListener {
}

// Raise data from cache if we have any documents or we are offline
return !snap.docs.isEmpty() || onlineState === OnlineState.Failed;
return !snap.docs.isEmpty() || onlineState === OnlineState.Offline;
}

private shouldRaiseEvent(snap: ViewSnapshot): boolean {
Expand Down
1 change: 1 addition & 0 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export class FirestoreClient {
this.remoteStore = new RemoteStore(
this.localStore,
datastore,
this.asyncQueue,
onlineStateChangedHandler
);

Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export enum OnlineState {
* reached after a successful connection and there has been at least one
* successful message received from the backends.
*/
Healthy,
Online,

/**
* The client is either trying to establish a connection but failing, or it
* has been explicitly marked offline via a call to disableNetwork().
* Higher-level components should operate in offline mode.
*/
Failed
Offline
}
2 changes: 1 addition & 1 deletion packages/firestore/src/core/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class View {
* ViewChange if the view's syncState changes as a result.
*/
applyOnlineStateChange(onlineState: OnlineState): ViewChange {
if (this.current && onlineState === OnlineState.Failed) {
if (this.current && onlineState === OnlineState.Offline) {
// If we're offline, set `current` to false and then call applyChanges()
// to refresh our syncState and generate a ViewChange as appropriate. We
// are guaranteed to get a new TargetChange that sets `current` back to
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/platform_node/grpc_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const LOG_TAG = 'Connection';
// TODO(b/38203344): The SDK_VERSION is set independently from Firebase because
// we are doing out-of-band releases. Once we release as part of Firebase, we
// should use the Firebase version instead.
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${
SDK_VERSION
} grpc/${grpcVersion}`;
const X_GOOG_API_CLIENT_VALUE = `gl-node/${
process.versions.node
} fire/${SDK_VERSION} grpc/${grpcVersion}`;

type DuplexRpc<Req, Resp> = () => grpc.ClientDuplexStream<Req, Resp>;
type ReadableRpc<Req, Resp> = (req: Req) => grpc.ClientReadableStream<Resp>;
Expand Down
Loading