Skip to content

test(metering): e2e usage invariants + integration-job coverage upload - #55

Merged
markovejnovic merged 6 commits into
mainfrom
test/usage
Jul 7, 2026
Merged

test(metering): e2e usage invariants + integration-job coverage upload#55
markovejnovic merged 6 commits into
mainfrom
test/usage

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

Codecov reported zero coverage on lib/hyper/metering/usage.ex. The gap was in coverage collection, not tests: test/hyper/metering/usage_test.exs already runs in CI's integration job, but only the elixir job uploaded coverage — and it excludes :external/:integration.

Changes

  • ci: the KVM integration job now runs mix coveralls.json --only integration --only external and uploads cover/excoveralls.json under a new integration Codecov flag (registered in codecov.yml; Codecov merges flags into the combined report).
  • test(e2e) vm_lifecycle: after stop_image_vm/1, Usage.total/1 is non-nil and positive (proves the Meter-last-child teardown flush end-to-end); every vm_usage row is well-formed (window_start < window_end, cpu_usec > 0, node attribution); total/3 over a half-open range covering all window_starts reproduces the lifetime total.
  • test(e2e) crash_recovery: after SIGKILL → cold-boot recovery → stop, Usage.total/1 is positive — if the accumulator went negative on the recreated cgroup's counter reset instead of re-baselining, every flush would be refused and the total would stay nil.
  • test(metering): consecutive half-open total/3 ranges with cuts exactly ON window_starts partition the lifetime total (the never-double-count billing claim; mutation-verified — both <=/< and >=/> boundary mutants fail the test).

Coverage triage (per CLAUDE.md)

Declined at test level: the rescue clause in Usage.insert/1 (Postgrex.Error / DBConnection.ConnectionError{:error, e}). Exercising it requires injecting a Postgres connection fault into the shared app Repo — fault-injection infrastructure disproportionate to two lines. The consumer-side contract (the Meter keeps accrued time and retries when the sink errors) is what protects billing.

The integration job ran mix test bare, so integration/external-only
modules (Hyper.Metering.Usage among them) uploaded zero coverage.
Wrap the run in coveralls.json and upload under a new 'integration'
Codecov flag; Codecov merges flags into the combined report.
stop_image_vm must leave a positive Usage.total: the Meter stops first
and flushes before the cgroup is removed. Also pins row well-formedness
(start < end, cpu_usec > 0, node attribution) and that total/3 over a
range covering all window_starts reproduces the lifetime total.
A recreated cgroup resets cpu.stat; if the accumulator went negative
instead of re-baselining, every flush would be refused and total/1
would stay nil. Assert a positive lifetime total after crash+stop.
Pins the moduledoc's never-double-count claim: half-open total/3 ranges
whose cuts land exactly on window_starts must sum to total/1.
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Test Results

  3 files  ±0  155 suites  ±0   2m 31s ⏱️ + 1m 4s
458 tests +1  458 ✅ +1    0 💤 ±0  0 ❌ ±0 
780 runs  +2  458 ✅ +1  322 💤 +1  0 ❌ ±0 

Results for commit 5363c32. ± Comparison against base commit 1e6bbd8.

♻️ This comment has been updated with latest results.

A periodic flush landing before the SIGKILL made the bare positive-total
assertion pass even with a broken post-crash re-baseline. Snapshot the
total before stop and require the teardown flush to strictly grow it.
@markovejnovic
markovejnovic merged commit e228b6a into main Jul 7, 2026
7 checks passed
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.

1 participant