You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: unified time testing with mutable TestClock and app_now() DB function
Implements a hybrid approach to unify time management across the Haskell
app layer and PostgreSQL database in tests, enabling time fast-forwarding
for timeseries data and background job testing.
Three components:
1. Mutable TestClock (src/Pkg/TestClock.hs):
- IORef-backed clock with advanceTime/setTestTime/getTestTime
- runMutableTime: custom Time effect interpreter reading from IORef
- runWithTimeSyncedPool: pool wrapper that sets DB GUC on each checkout
2. app_now() PostgreSQL function (migration 0033):
- Reads app.current_time GUC, falls back to NOW() in production
- Updated triggers: set_updated_at, new_anomaly_proc,
check_triggered_query_monitors, check_tests_to_trigger
3. NOW() replaced with ? parameters in 16 source files:
- All SQL queries now receive time from Time.currentTime effect
- Production uses real time; tests use mutable TestClock time
Test infrastructure updates:
- TestResources gains trTestClock field
- All test runners thread TestClock through effect stacks
- Replaced getCurrentTime with getTestTime in all test specs
- Added advanceTestTime/advanceMinutes/advanceHours/advanceDays helpers
https://claude.ai/code/session_019Mn7XLed4oq6j7dWqciekH
$Log.logInfo "Hourly jobs already scheduled for today, skipping"()
267
267
268
-
projects <-PG.query [sql|SELECT DISTINCT p.id FROM projects.projects p JOIN otel_logs_and_spans o ON o.project_id = p.id::text WHERE p.active = TRUE AND p.deleted_at IS NULL AND p.payment_plan != 'ONBOARDING' AND o.timestamp > now() - interval '24 hours'|] ()
268
+
projects <-PG.query [sql|SELECT DISTINCT p.id FROM projects.projects p JOIN otel_logs_and_spans o ON o.project_id = p.id::text WHERE p.active = TRUE AND p.deleted_at IS NULL AND p.payment_plan != 'ONBOARDING' AND o.timestamp > ? - interval '24 hours'|] (Only currentTime)
269
269
Log.logInfo "Scheduling jobs for projects" ("project_count", length projects)
270
270
forM_ projects \p ->do
271
271
-- Check if this project's jobs already scheduled for today (per-project idempotent check)
FROM (SELECT unnest(?::text[]) AS source_field, unnest(?::text[]) AS hash, unnest(?::text[]) AS state, unnest(?::float8[]) AS mean, unnest(?::float8[]) AS mad, unnest(?::int[]) AS samples) v
198
202
WHERE lp.project_id = ? AND lp.source_field = v.source_field AND lp.pattern_hash = v.hash
0 commit comments