Skip to content

Commit 8faf84d

Browse files
test: follow observation cursors past empty pages (#2099)
The e2e helper get_observations stopped on an empty page, which the observations v2 API can now return while meta.cursor is set. Two e2e tests also asserted no cursor for unbounded no-match queries, which depends on how fast the server scans back to 2020-01-01; bound them to the last day so the server covers the range in one scan window. Co-authored-by: Hassieb Pakzad <68423100+hassiebp@users.noreply.github.com>
1 parent 9e760d6 commit 8faf84d

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎tests/e2e/test_core_sdk.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,15 +1843,23 @@ def test_get_observations():
18431843

18441844

18451845
def test_get_observations_for_unknown_trace_is_empty():
1846-
response = get_api(retry=False).observations.get_many(trace_id=create_uuid())
1846+
# A lower bound within the server's first 7-day scan window makes one
1847+
# request cover the whole range, so the cursor is reliably absent.
1848+
response = get_api(retry=False).observations.get_many(
1849+
trace_id=create_uuid(),
1850+
from_start_time=datetime.now(timezone.utc) - timedelta(days=1),
1851+
)
18471852

18481853
assert response.data == []
18491854
assert response.meta.cursor is None
18501855

18511856

18521857
def test_get_observations_empty():
18531858
# Fetch observations with a filter that should return no results
1854-
response = get_api(retry=False).observations.get_many(name=create_uuid())
1859+
response = get_api(retry=False).observations.get_many(
1860+
name=create_uuid(),
1861+
from_start_time=datetime.now(timezone.utc) - timedelta(days=1),
1862+
)
18551863

18561864
assert response.data == []
18571865
assert response.meta.cursor is None

‎tests/support/utils.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def get_observations(
186186
)
187187
observations.extend(response.data)
188188
cursor = response.meta.cursor
189-
if not cursor or not response.data:
189+
# Pages can be short or empty before the end.
190+
if not cursor:
190191
break
191192

192193
# The events table can briefly return several rows for one span until

‎tests/unit/test_e2e_support.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ def test_user_metadata_drops_server_added_keys():
124124
assert user_metadata(observation) == {"key": "value"}
125125

126126

127-
def test_get_observations_follows_cursor_and_sorts_by_start_time(monkeypatch):
127+
def test_get_observations_follows_cursor_past_empty_pages_and_sorts(monkeypatch):
128128
calls = []
129129
pages = {
130-
None: _page([_observation(2), _observation(0)], cursor="next"),
131-
"next": _page([_observation(1)]),
130+
None: _page([_observation(2), _observation(0)], cursor="empty"),
131+
"empty": _page([], cursor="last"),
132+
"last": _page([_observation(1)]),
132133
}
133134

134135
def get_many(**kwargs):
@@ -140,7 +141,7 @@ def get_many(**kwargs):
140141
observations = get_observations(trace_id="trace-123")
141142

142143
assert [o.id for o in observations] == ["obs-0", "obs-1", "obs-2"]
143-
assert [call["cursor"] for call in calls] == [None, "next"]
144+
assert [call["cursor"] for call in calls] == [None, "empty", "last"]
144145
assert all(call["trace_id"] == "trace-123" for call in calls)
145146

146147

0 commit comments

Comments
 (0)