Skip to content

test: stabilize records and streams integration tests - #2816

Open
evertoncolling wants to merge 3 commits into
masterfrom
fix-records-streams-flaky-tests
Open

test: stabilize records and streams integration tests#2816
evertoncolling wants to merge 3 commits into
masterfrom
fix-records-streams-flaky-tests

Conversation

@evertoncolling

@evertoncolling evertoncolling commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Description

Fix cross-run contamination in the upsert test by scoping queries to each batch. Harden cleanup, stream creation races, consistency polling, and sync pagination with a cursor captured before ingestion.

Checklist:

  • Tests added/updated.
  • Documentation updated (test docstrings; no public API changes).
  • The PR title follows the Conventional Commit spec.

@evertoncolling
evertoncolling requested review from a team as code owners September 7, 2026 08:08

@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 the data modeling records integration tests to improve robustness against eventual consistency delays and slow CI environments. Key changes include updating assert_eventually to use a deadline-based timeout, introducing a RecordBatch dataclass to track stable cursors and filters, and adding comprehensive unit tests for these integration helpers. Feedback suggests using getattr with a fallback when retrieving the name of the assertion callable in assert_eventually to prevent potential AttributeError crashes.

Comment thread tests/tests_integration/test_api/test_data_modeling/test_records.py Outdated
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.66997% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.13%. Comparing base (298b46c) to head (56d0ad0).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
..._data_modeling/test_records_integration_helpers.py 99.38% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2816      +/-   ##
==========================================
- Coverage   93.15%   93.13%   -0.03%     
==========================================
  Files         516      518       +2     
  Lines       53665    53903     +238     
==========================================
+ Hits        49993    50203     +210     
- Misses       3672     3700      +28     
Files with missing lines Coverage Δ
tests/records_helpers.py 100.00% <100.00%> (ø)
...ration/test_api/test_data_modeling/test_records.py 100.00% <100.00%> (+0.86%) ⬆️
...s_unit/test_api/test_data_modeling/test_records.py 100.00% <100.00%> (ø)
..._data_modeling/test_records_integration_helpers.py 99.38% <99.38%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

from cognite.client.data_classes.data_modeling.aggregates import MetricResult
from cognite.client.data_classes.data_modeling.records import Record, RecordContainerId, RecordSource, RecordWrite
from cognite.client.exceptions import CogniteAPIError
from tests.tests_integration.test_api.test_data_modeling import test_records as integration

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.

Here is importing dependencies from integration test to unit tests. This is not common in this repo and it increases risks of slowing or polluting unit test if integration module brings heavy dependencies or side effects. also if integration test got refactored, it would break the unit tests as well. finally it is quite fragile to get pytest fixture through getattr(integration.mutable_stream, "__wrapped__"). I would suggest moving assert_eventually, RecordBatch, fixture core login to tests/tests_utils so integration and unit can refer them together.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point! I extracted the shared helpers on 56d0ad0

@evertoncolling evertoncolling added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Sep 7, 2026
def clock(monkeypatch: pytest.MonkeyPatch) -> list[float]:
now = [0.0]
monkeypatch.setattr(time, "monotonic", lambda: now[0])
monkeypatch.setattr(time, "sleep", lambda delay: now.__setitem__(0, now[0] + delay))

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.

This looks crazy tbh, why is it necessary?

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

Labels

waiting-for-risk-review Waiting for a member of the risk review team to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants