Skip to content

Commit 979ffd9

Browse files
committed
Added spec tests.
Two TODO: 1. load from secondary tab. 2. don't fail async queue.
1 parent db1d864 commit 979ffd9

File tree

6 files changed

+418
-6
lines changed

6 files changed

+418
-6
lines changed

packages/firestore/src/core/sync_engine.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,15 @@ export class SyncEngine implements RemoteSyncer {
447447
): Promise<void> {
448448
this.assertSubscribed('loadBundle()');
449449

450-
return this.loadBundleAsync(bundleReader, task).catch(reason => {
451-
task.failedWith(new Error(reason));
452-
});
450+
return (
451+
this.loadBundleAsync(bundleReader, task)
452+
// TODO(wuandy): Loading a bundle will fail the entire SDK if there is
453+
// an error. We really should have a way to run operations on async queue
454+
// and not failing the rest if there is an error.
455+
.catch(reason => {
456+
task.failedWith(reason);
457+
})
458+
);
453459
}
454460

455461
private async loadBundleAsync(
@@ -1323,4 +1329,11 @@ export class MultiTabSyncEngine extends SyncEngine
13231329
.catch(ignoreIfPrimaryLeaseLoss);
13241330
}
13251331
}
1332+
1333+
loadBundle(
1334+
bundleReader: BundleReader,
1335+
task: LoadBundleTaskImpl
1336+
): Promise<void> {
1337+
return super.loadBundle(bundleReader, task);
1338+
}
13261339
}

packages/firestore/src/local/local_store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ export class LocalStore {
646646
});
647647
return this.persistence.runTransaction(
648648
'Apply bundle documents',
649-
'readwrite-primary',
649+
'readwrite',
650650
txn => {
651651
return this.applyDocuments(
652652
documentBuffer,

packages/firestore/test/integration/api/bundle.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717

1818
import * as firestore from '@firebase/firestore-types';
1919
import { expect } from 'chai';
20-
import { apiDescribe, toDataArray, withTestDb } from '../util/helpers';
20+
import {
21+
apiDescribe,
22+
toDataArray,
23+
withAlternateTestDb,
24+
withTestDb
25+
} from '../util/helpers';
2126
import { TestBundleBuilder } from '../../util/bundle_data';
2227
import { DatabaseId } from '../../../src/core/database_info';
2328
import { key } from '../../util/helpers';
@@ -40,7 +45,7 @@ function verifyInProgress(
4045
expect(p.documentsLoaded).to.equal(expectedDocuments);
4146
}
4247

43-
apiDescribe.only('Bundles', (persistence: boolean) => {
48+
apiDescribe('Bundles', (persistence: boolean) => {
4449
const encoder = new TextEncoder();
4550
const testDocs: { [key: string]: firestore.DocumentData } = {
4651
a: { k: { stringValue: 'a' }, bar: { integerValue: 1 } },
@@ -224,4 +229,20 @@ apiDescribe.only('Bundles', (persistence: boolean) => {
224229
]);
225230
});
226231
});
232+
233+
it('load with documents from other projects fails.', () => {
234+
return withTestDb(persistence, async db => {
235+
const builder = bundleWithTestDocs(db);
236+
return withAlternateTestDb(persistence, async otherDb => {
237+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
238+
expect(
239+
otherDb.loadBundle(
240+
encoder.encode(
241+
builder.build('test-bundle', { seconds: 1001, nanos: 9999 })
242+
)
243+
)
244+
).to.be.rejectedWith('Tried to deserialize key from different project');
245+
});
246+
});
247+
});
227248
});

0 commit comments

Comments
 (0)