Skip to content

Test large documents #7040

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Test large documents #7040

wants to merge 3 commits into from

Conversation

milaGGL
Copy link
Contributor

@milaGGL milaGGL commented Jun 17, 2025

WIP: waiting for the backend to be able to handle large docs

Copy link
Contributor

Firebase AI Mock Responses Check ⚠️

A newer major version of the mock responses for Firebase AI unit tests is available. update_responses.sh should be updated to clone the latest version of the responses: v14.1

Copy link
Contributor

github-actions bot commented Jun 17, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @milaGGL, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive integration tests to validate the Firestore client's robustness when handling documents that are close to the maximum allowed size. The new tests cover fundamental data operations, transactional integrity, and real-time data synchronization via snapshot listeners, ensuring the client can reliably manage large data payloads.

Highlights

  • New Test Cases for Large Documents: I've added four new integration tests in FirestoreTest.java to thoroughly test the Firestore client's ability to handle documents approaching the maximum size limit. These tests cover various operations including basic CRUD, transactions, and snapshot listeners.
  • Large Document Content Generation: A new helper method, getLargestDocContent(), has been introduced in IntegrationTestUtil.java. This utility generates a Map containing a Blob field filled with random bytes, specifically sized to be just under Firestore's maximum document size limit, enabling realistic large document testing.
  • CRUD Operations with Large Documents: The testCanCRUDAndQueryLargeDocuments() test verifies that set, get, update, query, and delete operations function correctly when dealing with documents that are near the maximum allowed size.
  • Transaction Support for Large Documents: The testCanCRUDLargeDocumentsInsideTransaction() test ensures that large documents can be successfully read, updated, set, and deleted within a Firestore transaction, confirming atomicity and data integrity for large payloads.
  • Snapshot Listener Behavior with Large Documents: Two new tests, listenToLargeQuerySnapshot() and listenToLargeDocumentSnapshot(), validate that snapshot listeners correctly receive and process query and document snapshots containing large documents, ensuring real-time updates work as expected.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-oss-bot
Copy link
Contributor

1 Warning
⚠️ Did you forget to add a changelog entry? (Add the 'no-changelog' label to the PR to silence this warning.)

Generated by 🚫 Danger

@milaGGL milaGGL added the WIP label Jun 17, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The code changes introduce new tests to verify CRUD operations and snapshot listeners work correctly with large documents in Firestore. The tests cover basic CRUD operations, transactions, and both query and document snapshot listeners.

Comment on lines +1993 to +2021
@Test
public void testCanCRUDAndQueryLargeDocuments() {
CollectionReference collRef = testCollection();
DocumentReference docRef = collRef.document();
Map<String, Object> data = getLargestDocContent();

// Set
waitFor(docRef.set(data));

// Get
DocumentSnapshot snapshot = waitFor(docRef.get());
assertEquals(data, snapshot.getData());

// Update
Map<String, Object> newData = getLargestDocContent();
waitFor(docRef.update(newData));
snapshot = waitFor(docRef.get());
assertEquals(newData, snapshot.getData());

// Query
QuerySnapshot querySnapshot = waitFor(collRef.get());
assertEquals(querySnapshot.size(), 1);
assertEquals(newData, querySnapshot.getDocuments().get(0).getData());

// Delete
waitFor(docRef.delete());
snapshot = waitFor(docRef.get());
assertFalse(snapshot.exists());
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider extracting the common parts of these tests into helper methods to reduce code duplication and improve readability.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 17, 2025

Coverage Report 1

Affected Products

  • firebase-firestore

    Overall coverage changed from 45.78% (f08e0c7) to 45.76% (8850386) by -0.01%.

    FilenameBase (f08e0c7)Merge (8850386)Diff
    LruGarbageCollector.java97.27%93.64%-3.64%

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/2BsHnayZp9.html

Copy link
Contributor

github-actions bot commented Jun 17, 2025

Test Results

  186 files   -   872    186 suites   - 872   4m 26s ⏱️ - 31m 26s
1 235 tests  - 4 750  1 219 ✅  - 4 744  16 💤  -  6  0 ❌ ±0 
2 494 runs   - 9 539  2 462 ✅  - 9 527  32 💤  - 12  0 ❌ ±0 

Results for commit a08a955. ± Comparison against base commit f08e0c7.

This pull request removes 4750 tests.
com.google.android.datatransport.cct.CctBackendFactoryTest ‑ create_returnCCTBackend_WhenBackendNameIsCCT
com.google.android.datatransport.cct.CctDestinationTest ‑ cctDestination_shouldOnlySupportProtoAndJson
com.google.android.datatransport.cct.CctDestinationTest ‑ cctDestination_shouldSupportProtoAndJson
com.google.android.datatransport.cct.CctTransportBackendTest ‑ decorate_whenOffline_shouldProperlyPopulateNetworkInfo
com.google.android.datatransport.cct.CctTransportBackendTest ‑ decorate_whenOnline_shouldProperlyPopulateNetworkInfo
com.google.android.datatransport.cct.CctTransportBackendTest ‑ schedule_shouldAddCookieOnPseudonymousIds
com.google.android.datatransport.cct.CctTransportBackendTest ‑ schedule_shouldDropCookieOnMixedPseudonymousIds
com.google.android.datatransport.cct.CctTransportBackendTest ‑ send_CompressedResponseIsUncompressed
com.google.android.datatransport.cct.CctTransportBackendTest ‑ send_whenBackendRedirectsMoreThan5Times_shouldOnlyRedirect4Times
com.google.android.datatransport.cct.CctTransportBackendTest ‑ send_whenBackendRedirects_shouldCorrectlyFollowTheRedirectViaPost
…

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 17, 2025

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 17, 2025

Startup Time Report 1

Note: Layout is sometimes suboptimal due to limited formatting support on GitHub. Please check this report on GCS.

Notes

Startup Times

  • fire-fst

    DeviceStatisticsDistributions
    oriole-32
    Percentilef08e0c78850386DiffSignificant (?)
    p10264 ±12 μs254 ±12 μs-10.5 μs (-4.0%)NO
    p25277 ±12 μs265 ±15 μs-12.6 μs (-4.5%)NO
    p50307 ±35 μs292 ±41 μs-14.5 μs (-4.7%)NO
    p75360 ±72 μs351 ±81 μs-9.33 μs (-2.6%)NO
    p90445 ±124 μs421 ±104 μs-23.9 μs (-5.4%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    8850386
    • 2025-06-18_16:20:39.169329_gihc
    • 2025-06-18_16:20:39.169371_tfKe
    • 2025-06-18_16:20:39.169384_ANuG
    • 2025-06-18_16:20:39.169392_SuHe
    • 2025-06-18_16:20:39.169399_HaeP
    • 2025-06-18_16:20:39.169406_TYJB
    • 2025-06-18_16:20:39.169413_siYp
    • 2025-06-18_16:20:39.169419_JSgY
    • 2025-06-18_16:20:39.169425_eGmU
    • 2025-06-18_16:20:39.169431_ECYr
    redfin-30
    Percentilef08e0c78850386DiffSignificant (?)
    p10515 ±40 μs499 ±57 μs-15.8 μs (-3.1%)NO
    p25533 ±41 μs512 ±59 μs-21.9 μs (-4.1%)NO
    p50558 ±43 μs531 ±60 μs-27.3 μs (-4.9%)NO
    p75594 ±41 μs555 ±62 μs-38.6 μs (-6.5%)NO
    p90670 ±117 μs589 ±68 μs-81.0 μs (-12.1%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    8850386
    • 2025-06-18_16:20:39.169329_gihc
    • 2025-06-18_16:20:39.169371_tfKe
    • 2025-06-18_16:20:39.169384_ANuG
    • 2025-06-18_16:20:39.169392_SuHe
    • 2025-06-18_16:20:39.169399_HaeP
    • 2025-06-18_16:20:39.169406_TYJB
    • 2025-06-18_16:20:39.169413_siYp
    • 2025-06-18_16:20:39.169419_JSgY
    • 2025-06-18_16:20:39.169425_eGmU
    • 2025-06-18_16:20:39.169431_ECYr
  • timeToInitialDisplay

    DeviceStatisticsDistributions
    oriole-32
    Percentilef08e0c78850386DiffSignificant (?)
    p10199 ±4 ms198 ±2 ms-586 μs (-0.3%)NO
    p25204 ±4 ms204 ±2 ms-148 μs (-0.1%)NO
    p50211 ±4 ms211 ±2 ms+630 μs (+0.3%)NO
    p75218 ±4 ms219 ±2 ms+1.23 ms (+0.6%)NO
    p90226 ±4 ms229 ±5 ms+3.31 ms (+1.5%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    8850386
    • 2025-06-18_16:20:39.169329_gihc
    • 2025-06-18_16:20:39.169371_tfKe
    • 2025-06-18_16:20:39.169384_ANuG
    • 2025-06-18_16:20:39.169392_SuHe
    • 2025-06-18_16:20:39.169399_HaeP
    • 2025-06-18_16:20:39.169406_TYJB
    • 2025-06-18_16:20:39.169413_siYp
    • 2025-06-18_16:20:39.169419_JSgY
    • 2025-06-18_16:20:39.169425_eGmU
    • 2025-06-18_16:20:39.169431_ECYr
    redfin-30
    Percentilef08e0c78850386DiffSignificant (?)
    p10227 ±7 ms247 ±4 ms+20.3 ms (+9.0%)NO
    p25234 ±8 ms252 ±5 ms+18.4 ms (+7.9%)NO
    p50243 ±11 ms261 ±6 ms+17.3 ms (+7.1%)NO
    p75253 ±14 ms270 ±6 ms+17.1 ms (+6.8%)NO
    p90264 ±19 ms282 ±9 ms+18.3 ms (+6.9%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    8850386
    • 2025-06-18_16:20:39.169329_gihc
    • 2025-06-18_16:20:39.169371_tfKe
    • 2025-06-18_16:20:39.169384_ANuG
    • 2025-06-18_16:20:39.169392_SuHe
    • 2025-06-18_16:20:39.169399_HaeP
    • 2025-06-18_16:20:39.169406_TYJB
    • 2025-06-18_16:20:39.169413_siYp
    • 2025-06-18_16:20:39.169419_JSgY
    • 2025-06-18_16:20:39.169425_eGmU
    • 2025-06-18_16:20:39.169431_ECYr

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/hQJzEv8sP3/index.html

Copy link
Contributor

@ehsannas ehsannas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A minor nit pointed out below.

@@ -125,6 +128,10 @@ public enum TargetBackend {

private static boolean backendPrimed = false;

private static final Random RANDOM = new Random();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think it'd be better to move this into the getLargestDocContent() function.

final Random random = new Random();
random.nextBytes(bytes);

@@ -125,6 +128,10 @@ public enum TargetBackend {

private static boolean backendPrimed = false;

private static final Random RANDOM = new Random();

private static final int MAX_BYTES_PER_FIELD_VALUE = 1048487;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on the fence about moving this into getLargestDocContent(). On the one hand, literal constants are usually kept outside the method scope. On the other hand, there are no other usages of it. Leaning a bit towards keeping it here.

@ehsannas
Copy link
Contributor

Labeling the PR with do-not-merge until we update to the new/larger size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants