Skip to content

Commit 8bc241f

Browse files
Fix tests after merge
1 parent ae2fa31 commit 8bc241f

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ import {
7272
import { PersistencePromise } from './persistence_promise';
7373
import { ClientId } from './shared_client_state';
7474
import { TargetData } from './target_data';
75-
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';
75+
import {
76+
isIndexedDbTransactionError,
77+
SimpleDb,
78+
SimpleDbStore,
79+
SimpleDbTransaction
80+
} from './simple_db';
7681

7782
const LOG_TAG = 'IndexedDbPersistence';
7883

@@ -287,7 +292,7 @@ export class IndexedDbPersistence implements Persistence {
287292
// having the persistence lock), so it's the first thing we should do.
288293
return this.updateClientMetadataAndTryBecomePrimary();
289294
})
290-
.then(e => {
295+
.then(() => {
291296
if (!this.isPrimary && !this.allowTabSynchronization) {
292297
// Fail `start()` if `synchronizeTabs` is disabled and we cannot
293298
// obtain the primary lease.
@@ -423,7 +428,7 @@ export class IndexedDbPersistence implements Persistence {
423428
)
424429
.catch(e => {
425430
if (!this.allowTabSynchronization) {
426-
if (e.name === 'IndexedDbTransactionError') {
431+
if (isIndexedDbTransactionError(e)) {
427432
logDebug(LOG_TAG, 'Failed to extend owner lease: ', e);
428433
// Proceed with the existing state. Any subsequent access to
429434
// IndexedDB will verify the lease.

packages/firestore/src/local/local_store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { IndexedDbMutationQueue } from './indexeddb_mutation_queue';
6666
import { IndexedDbRemoteDocumentCache } from './indexeddb_remote_document_cache';
6767
import { IndexedDbTargetCache } from './indexeddb_target_cache';
6868
import { extractFieldMask } from '../model/object_value';
69+
import { isIndexedDbTransactionError } from './simple_db';
6970

7071
const LOG_TAG = 'LocalStore';
7172

@@ -727,7 +728,7 @@ export class LocalStore {
727728
}
728729
);
729730
} catch (e) {
730-
if (e.name === 'IndexedDbTransactionError') {
731+
if (isIndexedDbTransactionError(e)) {
731732
// If `notifyLocalViewChanges` fails, we did not advance the sequence
732733
// number for the documents that were included in this transaction.
733734
// This might trigger them to be deleted earlier than they otherwise

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ describe('IndexedDb: allowTabSynchronization', () => {
11441144
'clientA',
11451145
/* multiClient= */ false,
11461146
async db => {
1147-
db.injectFailures = true;
1147+
db.injectFailures = { updateClientMetadataAndTryBecomePrimary: true };
11481148
await expect(db.start()).to.eventually.be.rejectedWith(
11491149
'Failed to obtain exclusive access to the persistence layer.'
11501150
);
@@ -1158,7 +1158,7 @@ describe('IndexedDb: allowTabSynchronization', () => {
11581158
'clientA',
11591159
/* multiClient= */ true,
11601160
async db => {
1161-
db.injectFailures = true;
1161+
db.injectFailures = { updateClientMetadataAndTryBecomePrimary: true };
11621162
await db.start();
11631163
await db.shutdown();
11641164
}
@@ -1167,10 +1167,10 @@ describe('IndexedDb: allowTabSynchronization', () => {
11671167

11681168
it('ignores intermittent IndexedDbTransactionError during lease refresh', async () => {
11691169
await withPersistence('clientA', async (db, _, queue) => {
1170-
db.injectFailures = true;
1170+
db.injectFailures = { updateClientMetadataAndTryBecomePrimary: true };
11711171
await queue.runDelayedOperationsEarly(TimerId.ClientMetadataRefresh);
11721172
await queue.enqueue(() => {
1173-
db.injectFailures = false;
1173+
db.injectFailures = undefined;
11741174
return db.runTransaction('check success', 'readwrite-primary', () =>
11751175
PersistencePromise.resolve()
11761176
);

packages/firestore/test/unit/specs/spec_test_components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { expect } from 'chai';
5959
export class MockMemoryPersistence extends MemoryPersistence {
6060
injectFailures?: SpecDatabaseFailures;
6161

62-
runTransaction<T>(
62+
async runTransaction<T>(
6363
action: string,
6464
mode: PersistenceTransactionMode,
6565
transactionOperation: (
@@ -78,7 +78,7 @@ export class MockMemoryPersistence extends MemoryPersistence {
7878
export class MockIndexedDbPersistence extends IndexedDbPersistence {
7979
injectFailures?: SpecDatabaseFailures;
8080

81-
runTransaction<T>(
81+
async runTransaction<T>(
8282
action: string,
8383
mode: PersistenceTransactionMode,
8484
transactionOperation: (

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,8 @@ export type PersistenceAction =
12141214
| 'Lookup mutation documents'
12151215
| 'Get target data'
12161216
| 'Get new document changes'
1217-
| 'Synchronize last document change read time';
1217+
| 'Synchronize last document change read time'
1218+
| 'updateClientMetadataAndTryBecomePrimary';
12181219

12191220
/** Specifies failure or success for a list of database actions. */
12201221
export type SpecDatabaseFailures = Partial<

0 commit comments

Comments
 (0)