test: stabilize records and streams integration tests - #2816
test: stabilize records and streams integration tests#2816evertoncolling wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Fair point! I extracted the shared helpers on 56d0ad0
| 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)) |
There was a problem hiding this comment.
This looks crazy tbh, why is it necessary?
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: