-
Notifications
You must be signed in to change notification settings - Fork 903
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
Firestore: query.test.ts: use a different Firestore instance instead of a WriteBatch #7486
Firestore: query.test.ts: use a different Firestore instance instead of a WriteBatch #7486
Conversation
…of a WriteBatch to avoid affecting the local cache. This fixes the bug introduced by #7415 where WriteBatch affects the local cache (which I didn't realize).
|
Size Report 1Affected ProductsNo changes between base commit (223ac18) and merge commit (daf3069).Test Logs |
Size Analysis Report 1Affected ProductsNo changes between base commit (223ac18) and merge commit (daf3069).Test Logs |
Checking to see if this should be in the release notes. Is this a change related to a user issue? Should users expect a behavior change? |
No, this is just a fix to an integration test. No user behavior is affected. |
Ah, I see. My bad! Thanks. |
deletedDocumentIds.add(documentToDelete.id); | ||
} | ||
await writeBatchForDocumentDeletes.commit(); | ||
await withTestDb(PERSISTENCE_MODE_UNSPECIFIED, async db2 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this be returning the same Firestore instance(db === db2)? How it would help us avoid affecting cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question (I had to look into this too). But the answer is no because withTestDb()
creates and returns a newly-created, distinct Firestore
instance. Therefore, db
and db2
have distinct caches and do not share anything, and using db2
to delete/update documents does not affect the local cache of db
.
Here is the definition of withTestDb()
:
firebase-js-sdk/packages/firestore/test/lite/helpers.ts
Lines 57 to 61 in 223ac18
export function withTestDb( | |
fn: (db: Firestore) => void | Promise<void> | |
): Promise<void> { | |
return withTestDbSettings(DEFAULT_PROJECT_ID, DEFAULT_SETTINGS, fn); | |
} |
which calls withTestDbSettings()
:
firebase-js-sdk/packages/firestore/test/lite/helpers.ts
Lines 43 to 55 in 223ac18
export async function withTestDbSettings( | |
projectId: string, | |
settings: FirestoreSettings, | |
fn: (db: Firestore) => void | Promise<void> | |
): Promise<void> { | |
const app = initializeApp( | |
{ apiKey: 'fake-api-key', projectId }, | |
'test-app-' + appCount++ | |
); | |
const firestore = initializeFirestore(app, settings); | |
return fn(firestore); | |
} |
which creates a brand new FirestoreApp
with a unique name (the appCount
counter increments for each invocation) and then creates a brand new Firestore
object from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. So they are instances to a same firestore, but from different apps.
{ apiKey: 'fake-api-key', projectId },
'test-app-' + appCount++
);```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…lete documents instead of a transaction This is a port of firebase/firebase-js-sdk#7415 and firebase/firebase-js-sdk#7486
Use a different Firestore instance instead of a
WriteBatch
to avoid affecting the local cache inquery.test.ts
.I had originally thought that
WriteBatch
sidestepped the local cache, just like a transaction did; however, that turned out to be incorrect and using aWriteBatch
nullified the test cases that were modified to use it. This is a follow-up to #7415.This PR was ported to the Android SDK in firebase/firebase-android-sdk#5184 and to the iOS SDK in firebase/firebase-ios-sdk#11615.