-
Notifications
You must be signed in to change notification settings - Fork 19
ci: add code coverage #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
af07b43
7c45da7
ea184f9
2a975fc
3fde325
dd5590c
72af14b
cc30faf
6154b34
451b779
b279a60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,6 @@ on: | |
| - main | ||
| - release-* | ||
|
|
||
| schedule: | ||
| - cron: "0 6 * * *" | ||
|
|
||
| workflow_dispatch: | ||
| inputs: | ||
| full-matrix: | ||
|
|
@@ -252,6 +249,7 @@ jobs: | |
| run: bundle exec rake test | ||
| env: | ||
| SKIP_TLS_TESTS: ${{ matrix.host.OS == 'macos' && 'true' || '' }} | ||
| COVERAGE: "1" # Coverage is cheap so we compute it every run | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing reads the number this produces. Each matrix leg measures coverage inside its own workspace, prints it, and loses it when the job tears down. There is no artifact upload, no Writing the figure from The comment also overstates the reach. The Ruby 3.0 and 3.1 legs measure nothing, because |
||
|
|
||
| # Must run in its own process: the fork guard's precondition is that no | ||
| # command has been issued yet, which is false inside the shared suite. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # SimpleCov configuration | ||
| SimpleCov.configure do | ||
| suite = ENV["COV_GROUP"] || "all" | ||
|
|
||
| enable_coverage :branch | ||
| primary_coverage :line | ||
| command_name "test-#{suite}" | ||
| merging true | ||
| merge_timeout 3600 | ||
|
|
||
| skip %r{^/test/} | ||
| skip %r{^/valkey-glide/} # vendored upstream submodule, not our code | ||
| cover "lib/**/*.rb" # includes unloaded lib files and restricts the report to them | ||
|
|
||
| # tracked in https://github.com/valkey-io/valkey-glide-ruby/issues/307 | ||
| # reference_config = RUBY_PLATFORM.start_with?("x86_64-linux") && | ||
| # RUBY_VERSION.start_with?("3.4") && | ||
| # ENV["ENGINE_VERSION"] == "9.0" | ||
|
|
||
| # cluster runs last, so its report is the merge of all three suites. | ||
| project_total = suite == "cluster" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "cluster runs last" is true for
Checking that the merged set actually contains all three command names would be sturdier than relying on task order. |
||
|
|
||
| if reference_config && project_total | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Two things follow. Line 26 never runs, so no coverage threshold is ever applied on any leg. And this line is the Rubocop offence that makes CI red. I checked this by running the suite at this head. The warning is the first line of output on every test job: To show the block is unreachable I raised the threshold to Demanding 100% passes. Adding So the mechanism works and only the definition is missing. Uncommenting lines 18 to 20 fixes both the dead threshold and the lint. One warning: |
||
| minimum_coverage line: 80, branch: 70 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These thresholds sit below where coverage already is, so they cannot catch a realistic regression. I ran the full suite at this head and got line 88.46% and branch 71.54% (1629 tests, standalone plus cluster plus unit, merged). Against a floor of 80, line coverage can fall more than 8 points and still pass. This is also the ratchet @currantw asked for above, and SimpleCov ships it. expected_coverage line: 88, branch: 71That gets the behaviour from the C# repo without a custom mechanism. |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,21 @@ bundle exec rake test:standalone | |
| python3 valkey-glide/utils/cluster_manager.py --tls stop --prefix tls-standalone | ||
| ``` | ||
|
|
||
| ## Test Coverage | ||
|
|
||
| We measure both **line coverage** and **branch coverage** with [SimpleCov](https://github.com/simplecov-ruby/simplecov). Coverage is opt-in via the `COVERAGE` environment variable; when set, the test suite writes an HTML report to `coverage/index.html` and a machine-readable summary to `coverage/.last_run.json`. The `coverage/` directory is gitignored. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A contributor cannot learn from this what their coverage needs to be. The section explains how to produce a report, which is good, but it leaves out the three things someone about to open a PR actually needs: what number is expected, that nothing currently fails on it, and that the thresholds apply to one CI configuration rather than all of them. Suggested addition after this paragraph: CI measures coverage on every test job but does not fail on a drop yet. The
thresholds in `.simplecov` are 80% line and 70% branch, and they apply only to
the reference configuration. Issue #307 tracks turning this into a real gate.Three smaller corrections in the block below:
|
||
|
|
||
| ```bash | ||
| # Standalone only | ||
| COVERAGE=1 bundle exec rake test:standalone | ||
|
|
||
| # Full suite (standalone + cluster) | ||
| COVERAGE=1 bundle exec rake test | ||
|
|
||
| # Coverage report (MacOS) | ||
| open coverage/index.html | ||
| ``` | ||
|
|
||
| ## RuboCop | ||
|
|
||
| ```bash | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
|
|
||
| # Valkey GLIDE for Ruby | ||
|
|
||
| [](https://github.com/valkey-io/valkey-glide-ruby/actions/workflows/ci.yml?query=branch%3Amain) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These badges are worth having, but none of them is about coverage, which makes them scope creep in a coverage PR. The gap is also conspicuous: this is the one PR where a coverage badge would belong, and there is no way to add one yet because the figure is never published anywhere (see my note on the Either add a coverage badge once the number is published, or move these three to their own PR so this one stays focused. |
||
| [](https://rubygems.org/gems/valkey-glide-rb) | ||
| [](https://github.com/valkey-io/valkey-glide-ruby/blob/main/LICENSE) | ||
|
|
||
| Valkey General Language Independent Driver for the Enterprise (GLIDE) is the official open-source Valkey client library, part of the [Valkey](https://valkey.io) organization. The Ruby gem (`valkey-glide-rb`) wraps [Valkey GLIDE Core](https://github.com/valkey-io/valkey-glide), giving Ruby applications the performance and reliability of the GLIDE core. | ||
|
|
||
| ## Features | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,13 @@ | |
| # This is useful for CD testing to verify the published gem works correctly | ||
| $LOAD_PATH.unshift File.expand_path("../lib", __dir__) unless ENV["TEST_INSTALLED_GEM"] | ||
|
|
||
| # We use SimpleCov expected_coverage option, which requires SimpleCov 1.0 which needs | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment points at the wrong option. The config uses The second sentence is also wrong about cause. Reaching 80% coverage would not let Ruby 3.0 or 3.1 measure anything, because the gem itself refuses to install: simplecov 1.2.0 declares Suggested replacement for lines 7 and 8: # SimpleCov 1.x needs Ruby 3.2, so the 3.0 and 3.1 legs measure nothing.
# Drop this guard when those versions are no longer supported.Separately, |
||
| # Ruby 3.2. Enable for Ruby 3.0 and 3.1 once coverage reaches 80%. | ||
| if ENV["COVERAGE"] && RUBY_VERSION >= "3.2" | ||
| require "simplecov" | ||
| SimpleCov.start | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The load order here is correct and load bearing, so this is worth keeping as is. I checked the counterfactual: moving these three lines below One file still escapes, though. The |
||
| end | ||
|
|
||
| require "valkey" | ||
| require_relative "support/test_cluster" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two problems in the
on:block, both worth fixing before merge.The nightly
scheduletrigger is gone, and that looks unrelated to coverage. It also strands the branch on line 91, which testsEVENT_NAME == "schedule"to select the full matrix and the macOS runners. With noscheduletrigger nothing can reach that branch, so the full matrix now only runs on a manual dispatch or aworkflow_call. Was this a temporary change so cron runs would not fire while you iterated? If so, please restore it..simplecovis not in thepull_requestpaths filter above. The filter listsGemfile,Rakefileandvalkey.gemspec, but not the new config file, so a PR that only edits.simplecovruns no CI at all. That is exactly the PR shape the ratchet workflow produces: bump the threshold, change nothing else. Please add- .simplecovto the list.