Repository navigation
test: pin run_started_at in integration tests to avoid midnight flakes - #1079
Conversation
Tests build their data dates from utcnow(), but Elementary's buckets use dbt's run_started_at, which is set only after the data is seeded. When UTC midnight passed during seeding, the two disagreed by a day and date-based anomaly tests failed. DbtProject.test now passes custom_run_started_at, taken at the start of each call before seeding, unless the test already sets it. Each call gets its own time, so tests that run dbt several times still see time move forward. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
👋 @EladBarkay |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. 📝 WalkthroughWalkthrough
ChangesTest variable defaults
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~8 minutes Change: Other Merge Risk: ⚪ Minimal · up to No actionable issue was found in the run-start handling or its integration tests. The PR appears ready to merge, subject to normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The seeded table is named after the test id, and the old names made it 79 characters, so dbt seed failed on Postgres. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Integration tests fail at random when a CI run crosses UTC midnight. PR #1076's run started at 23:38 UTC, and 7 of its 8 failed jobs failed in the first 2.5 minutes after midnight, each on a different date-based test (dimension anomalies, volume anomalies, volume threshold, metric stability). They all passed on rerun.
Cause: tests build their data dates from
datetime.utcnow(), but Elementary's buckets use dbt'srun_started_at(get_detection_end), which is set only whendbt teststarts. Before that,DbtProject.testseeds the data, which can take minutes on cloud warehouses. If midnight passes in between, the data and the buckets are a day apart.Fix:
DbtProject.testnow passescustom_run_started_at, which the macros already support, set to the time the call starts, before seeding. Tests that already set it keep their own value. The time is taken per call, not per test, so tests that run dbt several times still see time move forward.test_volume_anomalies_no_timestampneeds that: a per-test time made its five runs collapse into one data point.test_varsis now copied, so a dict reused across calls can't freeze the time.Only the test harness changes. The package macros don't change.
Testing
utcnow()a day back intest_dimension_anomalies_with_timestamp_exclude_final_results:assert 'pass' == 'fail', the same error as trino/spark/dremio in fix: don't hide drops (or spikes) when ignore_small_changes sets only one threshold #1076's CI🤖 Generated with Claude Code
Summary by CodeRabbit