Skip to content

Commit 49016de

Browse files
committed
Merge branch 'master' into log
Mocha version in branch has updated to 5.2.0.
2 parents 63f8809 + 249dab2 commit 49016de

File tree

23 files changed

+198
-47
lines changed

23 files changed

+198
-47
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ packages/storage @schmidt-sebastian
1919
packages/storage-types @schmidt-sebastian
2020

2121
# Messaging Code
22-
packages/messaging @gauntface @pinarx @mmermerkaya @dwoffinden
23-
packages/messaging-types @gauntface @pinarx @mmermerkaya @dwoffinden
24-
integration/messaging @gauntface @pinarx @mmermerkaya @dwoffinden
22+
packages/messaging @pinarx @mmermerkaya @dwoffinden
23+
packages/messaging-types @pinarx @mmermerkaya @dwoffinden
24+
integration/messaging @pinarx @mmermerkaya @dwoffinden
2525

2626
# Auth Code
2727
packages/auth @bojeil-google @wti806

integration/browserify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"karma-sauce-launcher": "1.2.0",
2323
"karma-spec-reporter": "0.0.32",
2424
"mkdirp": "0.5.1",
25-
"mocha": "5.0.5"
25+
"mocha": "5.2.0"
2626
}
2727
}

integration/firestore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"karma-firefox-launcher": "1.1.0",
2222
"karma-mocha": "1.3.0",
2323
"karma-spec-reporter": "0.0.32",
24-
"mocha": "5.0.5",
24+
"mocha": "5.2.0",
2525
"ts-loader": "3.5.0",
2626
"typescript": "2.8.1",
2727
"webpack": "3.11.0",

integration/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"chromedriver": "2.37.0",
1616
"express": "4.16.3",
1717
"geckodriver": "1.11.0",
18-
"mocha": "5.0.5",
18+
"mocha": "5.2.0",
1919
"node-fetch": "2.1.2",
2020
"selenium-assistant": "5.3.0",
2121
"sinon": "4.5.0"

integration/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"karma-sauce-launcher": "1.2.0",
2424
"karma-spec-reporter": "0.0.32",
2525
"karma-typescript": "3.0.12",
26-
"mocha": "5.0.5",
26+
"mocha": "5.2.0",
2727
"npm-run-all": "4.1.2",
2828
"typescript": "2.8.1"
2929
}

integration/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"karma-mocha": "1.3.0",
2121
"karma-sauce-launcher": "1.2.0",
2222
"karma-spec-reporter": "0.0.32",
23-
"mocha": "5.0.5",
23+
"mocha": "5.2.0",
2424
"webpack": "3.11.0"
2525
}
2626
}

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"karma-sourcemap-loader": "0.3.7",
4343
"karma-spec-reporter": "0.0.32",
4444
"karma-webpack": "2.0.9",
45-
"mocha": "5.0.5",
45+
"mocha": "5.2.0",
4646
"npm-run-all": "4.1.2",
4747
"nyc": "11.6.0",
4848
"rollup": "0.57.1",

packages/database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"karma-sourcemap-loader": "0.3.7",
4545
"karma-spec-reporter": "0.0.32",
4646
"karma-webpack": "2.0.9",
47-
"mocha": "5.0.5",
47+
"mocha": "5.2.0",
4848
"npm-run-all": "4.1.2",
4949
"nyc": "11.6.0",
5050
"rollup": "0.57.1",

packages/database/test/helpers/EventAccumulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
export const EventAccumulatorFactory = {
1818
waitsForCount: maxCount => {
1919
let count = 0;
20-
const condition = () => ea.eventData.length >= count;
20+
const condition = () => count >= maxCount;
2121
const ea = new EventAccumulator(condition);
2222
ea.onReset(() => {
2323
count = 0;

packages/firestore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"karma-webpack": "2.0.9",
5656
"long": "3.2.0",
5757
"mkdirp": "0.5.1",
58-
"mocha": "5.0.5",
58+
"mocha": "5.2.0",
5959
"npm-run-all": "4.1.2",
6060
"nyc": "11.6.0",
6161
"prettier": "1.12.0",

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { SnapshotVersion } from '../core/snapshot_version';
2323
import { BATCHID_UNKNOWN } from '../model/mutation_batch';
2424
import { encode, EncodedResourcePath } from './encoded_resource_path';
2525
import { removeMutationBatch } from './indexeddb_mutation_queue';
26+
import { getHighestListenSequenceNumber } from './indexeddb_query_cache';
2627
import { dbDocumentSize } from './indexeddb_remote_document_cache';
2728
import { LocalSerializer } from './local_serializer';
2829
import { PersistencePromise } from './persistence_promise';
@@ -39,8 +40,10 @@ import { SimpleDbSchemaConverter, SimpleDbTransaction } from './simple_db';
3940
* https://github.com/firebase/firebase-ios-sdk/issues/1548
4041
* 4. Multi-Tab Support.
4142
* 5. Removal of held write acks.
43+
* 6. Create document global for tracking document cache size.
44+
* 7. Ensure every cached document has a sentinel row with a sequence number.
4245
*/
43-
export const SCHEMA_VERSION = 6;
46+
export const SCHEMA_VERSION = 7;
4447

4548
/** Performs database creation and schema upgrades. */
4649
export class SchemaConverter implements SimpleDbSchemaConverter {
@@ -115,6 +118,10 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
115118
});
116119
}
117120

121+
if (fromVersion < 7 && toVersion >= 7) {
122+
p = p.next(() => this.ensureSequenceNumbers(txn));
123+
}
124+
118125
return p;
119126
}
120127

@@ -172,6 +179,53 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
172179
});
173180
});
174181
}
182+
183+
/**
184+
* Ensures that every document in the remote document cache has a corresponding sentinel row
185+
* with a sequence number. Missing rows are given the most recently used sequence number.
186+
*/
187+
private ensureSequenceNumbers(
188+
txn: SimpleDbTransaction
189+
): PersistencePromise<void> {
190+
const documentTargetStore = txn.store<
191+
DbTargetDocumentKey,
192+
DbTargetDocument
193+
>(DbTargetDocument.store);
194+
const documentsStore = txn.store<DbRemoteDocumentKey, DbRemoteDocument>(
195+
DbRemoteDocument.store
196+
);
197+
198+
return getHighestListenSequenceNumber(txn).next(currentSequenceNumber => {
199+
const writeSentinelKey = (
200+
path: ResourcePath
201+
): PersistencePromise<void> => {
202+
return documentTargetStore.put(
203+
new DbTargetDocument(0, encode(path), currentSequenceNumber)
204+
);
205+
};
206+
207+
const promises: Array<PersistencePromise<void>> = [];
208+
return documentsStore
209+
.iterate((key, doc) => {
210+
const path = new ResourcePath(key);
211+
const docSentinelKey = sentinelKey(path);
212+
promises.push(
213+
documentTargetStore.get(docSentinelKey).next(maybeSentinel => {
214+
if (!maybeSentinel) {
215+
return writeSentinelKey(path);
216+
} else {
217+
return PersistencePromise.resolve();
218+
}
219+
})
220+
);
221+
})
222+
.next(() => PersistencePromise.waitFor(promises));
223+
});
224+
}
225+
}
226+
227+
function sentinelKey(path: ResourcePath): DbTargetDocumentKey {
228+
return [0, encode(path)];
175229
}
176230

177231
// TODO(mikelehen): Get rid of "as any" if/when TypeScript fixes their types.

packages/firestore/src/platform_node/grpc_connection.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,17 @@ export class GrpcConnection implements Connection {
113113
? grpc.credentials.createSsl()
114114
: grpc.credentials.createInsecure();
115115
this.cachedStub = {
116-
stub: new this.firestore.Firestore(this.databaseInfo.host, credentials),
116+
stub: new this.firestore.Firestore(
117+
this.databaseInfo.host,
118+
credentials,
119+
{
120+
// We do our own connection backoff (that for example is aware of whether or
121+
// not a write stream error is permanent or not) so we don't want gRPC to do
122+
// backoff on top of that. 100ms is the minimum value that gRPC allows.
123+
'grpc.initial_reconnect_backoff_ms': 100,
124+
'grpc.max_reconnect_backoff_ms': 100
125+
}
126+
),
117127
token
118128
};
119129
}

packages/firestore/test/unit/local/indexeddb_persistence.test.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { expect } from 'chai';
1818
import { PersistenceSettings } from '../../../src/api/database';
1919
import { SnapshotVersion } from '../../../src/core/snapshot_version';
20+
import { decode, encode } from '../../../src/local/encoded_resource_path';
2021
import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
2122
import {
2223
DbDocumentMutation,
@@ -32,6 +33,8 @@ import {
3233
DbRemoteDocumentGlobalKey,
3334
DbRemoteDocumentKey,
3435
DbTarget,
36+
DbTargetDocument,
37+
DbTargetDocumentKey,
3538
DbTargetGlobal,
3639
DbTargetGlobalKey,
3740
DbTargetKey,
@@ -521,6 +524,92 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
521524
});
522525
});
523526
});
527+
528+
it('can upgrade from version 6 to 7', async () => {
529+
const oldSequenceNumber = 1;
530+
// Set the highest sequence number to this value so that untagged documents
531+
// will pick up this value.
532+
const newSequenceNumber = 2;
533+
await withDb(6, db => {
534+
const serializer = TEST_SERIALIZER;
535+
536+
const sdb = new SimpleDb(db);
537+
return sdb.runTransaction('readwrite', V6_STORES, txn => {
538+
const targetGlobalStore = txn.store<DbTargetGlobalKey, DbTargetGlobal>(
539+
DbTargetGlobal.store
540+
);
541+
const remoteDocumentStore = txn.store<
542+
DbRemoteDocumentKey,
543+
DbRemoteDocument
544+
>(DbRemoteDocument.store);
545+
const targetDocumentStore = txn.store<
546+
DbTargetDocumentKey,
547+
DbTargetDocument
548+
>(DbTargetDocument.store);
549+
return targetGlobalStore
550+
.get(DbTargetGlobal.key)
551+
.next(metadata => {
552+
expect(metadata).to.not.be.null;
553+
metadata!.highestListenSequenceNumber = newSequenceNumber;
554+
return targetGlobalStore.put(DbTargetGlobal.key, metadata!);
555+
})
556+
.next(() => {
557+
// Set up some documents (we only need the keys)
558+
// For the odd ones, add sentinel rows.
559+
const promises: Array<PersistencePromise<void>> = [];
560+
for (let i = 0; i < 10; i++) {
561+
const document = doc('docs/doc_' + i, 1, { foo: 'bar' });
562+
promises.push(
563+
remoteDocumentStore.put(
564+
document.key.path.toArray(),
565+
serializer.toDbRemoteDocument(document)
566+
)
567+
);
568+
if (i % 2 === 1) {
569+
promises.push(
570+
targetDocumentStore.put(
571+
new DbTargetDocument(
572+
0,
573+
encode(document.key.path),
574+
oldSequenceNumber
575+
)
576+
)
577+
);
578+
}
579+
}
580+
return PersistencePromise.waitFor(promises);
581+
});
582+
});
583+
});
584+
585+
// Now run the migration and verify
586+
await withDb(7, db => {
587+
const sdb = new SimpleDb(db);
588+
return sdb.runTransaction('readonly', V6_STORES, txn => {
589+
const targetDocumentStore = txn.store<
590+
DbTargetDocumentKey,
591+
DbTargetDocument
592+
>(DbTargetDocument.store);
593+
const range = IDBKeyRange.bound(
594+
[0],
595+
[1],
596+
/*lowerOpen=*/ false,
597+
/*upperOpen=*/ true
598+
);
599+
return targetDocumentStore.iterate(
600+
{ range },
601+
([_, path], targetDocument) => {
602+
const decoded = decode(path);
603+
const lastSegment = decoded.lastSegment();
604+
const docNum = +lastSegment.split('_')[1];
605+
const expected =
606+
docNum % 2 === 1 ? oldSequenceNumber : newSequenceNumber;
607+
expect(targetDocument.sequenceNumber).to.equal(expected);
608+
}
609+
);
610+
});
611+
});
612+
});
524613
});
525614

526615
describe('IndexedDb: canActAsPrimary', () => {

packages/functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"karma-sourcemap-loader": "0.3.7",
4040
"karma-spec-reporter": "0.0.32",
4141
"karma-webpack": "2.0.9",
42-
"mocha": "5.0.5",
42+
"mocha": "5.2.0",
4343
"npm-run-all": "4.1.2",
4444
"nyc": "11.6.0",
4545
"rollup": "0.57.1",

packages/logger/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"karma-sauce-launcher": "1.2.0",
3232
"karma-spec-reporter": "0.0.32",
3333
"karma-webpack": "2.0.9",
34-
"mocha": "5.0.5",
34+
"mocha": "5.2.0",
3535
"npm-run-all": "4.1.2",
3636
"nyc": "11.6.0",
3737
"rollup": "0.57.1",

packages/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"karma-sauce-launcher": "1.2.0",
4444
"karma-sourcemap-loader": "0.3.7",
4545
"karma-spec-reporter": "0.0.32",
46-
"mocha": "5.0.5",
46+
"mocha": "5.2.0",
4747
"npm-run-all": "4.1.2",
4848
"rollup": "0.57.1",
4949
"rollup-plugin-commonjs": "9.1.0",

packages/rxfire/docs/database.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ list(ref).subscribe(changes => {
8080
list(ref)
8181
.pipe(
8282
map(changes => changes.map(c => {
83-
return { _key: c.snapshot.key, event: c.event, ...c.snapshot.val(); };
84-
))
83+
return { _key: c.snapshot.key, event: c.event, ...c.snapshot.val() }
84+
})
8585
)
8686
.subscribe(users => { console.log(users); })
8787

packages/rxfire/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"karma-sourcemap-loader": "0.3.7",
5858
"karma-spec-reporter": "0.0.32",
5959
"karma-webpack": "2.0.9",
60-
"mocha": "5.0.5",
60+
"mocha": "5.2.0",
6161
"npm-run-all": "4.1.2",
6262
"nyc": "11.6.0",
6363
"sinon": "4.5.0",

packages/template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"karma-sauce-launcher": "1.2.0",
4141
"karma-spec-reporter": "0.0.32",
4242
"karma-webpack": "2.0.9",
43-
"mocha": "5.0.5",
43+
"mocha": "5.2.0",
4444
"npm-run-all": "4.1.2",
4545
"nyc": "11.6.0",
4646
"rollup": "0.57.1",

packages/testing/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export {
2424
apps,
2525
assertFails,
2626
assertSucceeds,
27+
database,
28+
firestore,
2729
initializeAdminApp,
2830
initializeTestApp,
2931
loadDatabaseRules,
30-
loadFirestoreRules
32+
loadFirestoreRules,
3133
} from './src/api';

packages/testing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"devDependencies": {
2626
"chai": "4.1.2",
2727
"chai-as-promised": "7.1.1",
28-
"mocha": "5.0.5",
28+
"mocha": "5.2.0",
2929
"nyc": "13.1.0",
3030
"rollup": "0.57.1",
3131
"rollup-plugin-commonjs": "9.1.0",

packages/util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"karma-sauce-launcher": "1.2.0",
3535
"karma-spec-reporter": "0.0.32",
3636
"karma-webpack": "2.0.9",
37-
"mocha": "5.0.5",
37+
"mocha": "5.2.0",
3838
"npm-run-all": "4.1.2",
3939
"nyc": "11.6.0",
4040
"rollup": "0.57.1",

0 commit comments

Comments
 (0)