Skip to content

chore(firestore): fix firestore flaky tests#17439

Open
ohmayr wants to merge 4 commits into
mainfrom
fix-firestore-flakiness
Open

chore(firestore): fix firestore flaky tests#17439
ohmayr wants to merge 4 commits into
mainfrom
fix-firestore-flakiness

Conversation

@ohmayr

@ohmayr ohmayr commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes: #17428

Additional change: using 10 workers instead of auto seems to be a sweet spot.

@ohmayr ohmayr requested a review from a team as a code owner June 12, 2026 01:54

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several Firestore system tests to replace fragile sleep delays and polling loops with event-driven synchronization using concurrent.futures.Future. The review feedback highlights two issues: in test_watch_query_order, the future is resolved prematurely on the first snapshot callback instead of waiting for all 5 documents, and in test_create_document_w_vector, accumulating results with += in on_snapshot can lead to duplicate documents and should be replaced by direct assignment.

Comment on lines +2790 to +2791
if not five_docs_future.done():
five_docs_future.set_result(True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The future is currently resolved on the very first snapshot callback, regardless of how many documents are returned. Since the test writes 5 documents and expects to verify their ordering, resolving the future prematurely when len(docs) < 5 will cause the test to pass without actually verifying the ordering of all 5 documents. We should only resolve the future when len(docs) == 5.

Suggested change
if not five_docs_future.done():
five_docs_future.set_result(True)
if len(docs) == 5 and not five_docs_future.done():
five_docs_future.set_result(True)

Comment on lines 394 to +397
def on_snapshot(docs, changes, read_time):
on_snapshot.results += docs
if len(on_snapshot.results) >= 3 and not vector_query_future.done():
vector_query_future.set_result(True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using += to accumulate results in on_snapshot can lead to duplicate documents if multiple snapshots are delivered. Instead, assign the latest docs list directly to on_snapshot.results and check its length to resolve the future safely.

Suggested change
def on_snapshot(docs, changes, read_time):
on_snapshot.results += docs
if len(on_snapshot.results) >= 3 and not vector_query_future.done():
vector_query_future.set_result(True)
def on_snapshot(docs, changes, read_time):
on_snapshot.results = docs
if len(docs) >= 3 and not vector_query_future.done():
vector_query_future.set_result(True)

@ohmayr ohmayr requested a review from a team as a code owner June 12, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve flaky firestore tests

1 participant