Fix flaky test_read_timerange (assert filtering invariants, not a hard count)#95
Merged
Merged
Conversation
…d count test_read_timerange wrote 200 points through the async write queue and asserted the read back == 200. The queue's worker swallows the occasional failed write (e.g. a transient SQLite error on a loaded CI runner) but still marks the task done, so QUEUE.join() returns with fewer than 200 rows and the assertion flaked (seen as 200 == 175 / 183 on pytest-sdk). The prior fix (unique timestamps, 841d194) removed PK self-collisions but not this drop path. This test's job is the from_time/to_time filtering, not durable row counts (test_continuous_storing_of_and_reading_of_variables covers storage). Assert the filtering invariants against the actual stored set instead of a hard-coded 200: the three open/closed full-window forms must agree, and a midpoint-bounded read must be a strict, non-empty subset. Immune to an occasional dropped write. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pytest-sdkintermittently fails ondevelop(and only there — frontend PRs #93/#94 don't touch the SDK):Root cause
test_read_timerangewrites 200 points through the async write queue (db.write_to_ts→QUEUE) then asserts the read-back== 200. The queue worker (_writer) wraps each per-row commit inexcept Exception: LOGGER.exception(...)and still callsQUEUE.task_done(), so a transient write failure (e.g. SQLite under load on a busy CI runner) silently drops a row whileQUEUE.join()still reports "done". The result is< 200rows and a flaky hard-coded assertion.Verified empirically that it is not cross-test contamination (data does not survive the
databasefixture teardown) and not timestamp PK self-collision (the timestamps are mathematically unique). The prior fix841d194(unique timestamps) removed PK collisions but not this drop path.Fix
This test's purpose is the
from_time/to_timefiltering, not durable row counts (test_continuous_storing_of_and_reading_of_variablescovers storage). Assert the filtering invariants against the actual stored set instead of a hard-coded 200:[before, after], openfrom_time, opento_time) must return the same set — exercises thedatetime.min/utcnow()defaults;These hold regardless of an occasional dropped write, so the test can't flake on it, while still fully covering the filtering behaviour.
Verification
🤖 Generated with Claude Code