Skip to content

test: pin run_started_at in integration tests to avoid midnight flakes - #1079

Merged
EladBarkay merged 5 commits into
masterfrom
pin-run-started-at-in-integration-tests
Oct 6, 2026
Merged

EladBarkay merged 5 commits into
masterfrom
pin-run-started-at-in-integration-tests

Conversation

@EladBarkay

@EladBarkay EladBarkay commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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's run_started_at (get_detection_end), which is set only when dbt test starts. Before that, DbtProject.test seeds 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.test now passes custom_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_timestamp needs that: a per-test time made its five runs collapse into one data point. test_vars is 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

  • Full integration suite on DuckDB locally: 253 passed, 22 skipped.
  • Simulated a midnight crossing locally by shifting utcnow() a day back in test_dimension_anomalies_with_timestamp_exclude_final_results:
  • pre-commit hooks pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Test runs now receive a UTC start timestamp when one is not provided, while preserving explicitly supplied timestamps. Reusing test variables no longer changes the caller’s dictionary, and each run can receive a fresh timestamp.
  • Tests
    • Expanded integration coverage for default and caller-provided timestamps, reuse of test variables across runs, and time-bucket statuses for spikes near UTC midnight.

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>
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

👋 @EladBarkay
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 40768f8a-3948-48ee-a683-74923bb648cd
📥 Commits

Reviewing files that changed from the base of the PR and between 8b39151 and 8a790d0.

📒 Files selected for processing (1)
  • integration_tests/tests/test_run_started_at.py

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.


📝 Walkthrough

Walkthrough

DbtProject.test now copies the supplied test_vars before setting elementary_enabled. It also defaults custom_run_started_at to the current UTC timestamp in ISO format when the variable is not already set.

Changes

Test variable defaults

Layer / File(s) Summary
Prepare test variables
integration_tests/tests/dbt_project.py
DbtProject.test copies test_vars, sets elementary_enabled on the copy, and adds custom_run_started_at only when it is absent.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 8a790

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the integration-test change: pinning run_started_at to prevent midnight-related flakes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

EladBarkay and others added 2 commits October 6, 2026 13:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EladBarkay
EladBarkay enabled auto-merge October 6, 2026 16:20
EladBarkay and others added 2 commits October 6, 2026 19:21
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>
@EladBarkay
EladBarkay merged commit d93d567 into master Oct 6, 2026
29 of 31 checks passed
@EladBarkay
EladBarkay deleted the pin-run-started-at-in-integration-tests branch October 6, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants