Skip to content

chore: overhaul the test suite - #147

Merged
rustatian merged 6 commits into
masterfrom
chore/overhaul-test-suite
Aug 18, 2026
Merged

chore: overhaul the test suite#147
rustatian merged 6 commits into
masterfrom
chore/overhaul-test-suite

Conversation

@rustatian

Copy link
Copy Markdown
Member

Wave 2 overhaul. 797 lines and 17 tests, each opening with the same ~45 lines of endure boilerplate.

Two tests asserted nothing meaningful.

TestOnInitMetrics ran the on_init script that declares a prometheus collector over rpc, then booted and stopped without checking anything — a script that declared nothing would have passed. It now scrapes the metrics endpoint and requires foo_bar_test to be present.

TestAppNoAppSectionInConfig loaded configs/.rr-wrong-command.yaml, which made it a duplicate of TestAppWrongCommand. The .rr-no-app-section.yaml it was named after does have a server section, so the name never described either file. Dropped the duplicate test and the misnamed config.

Two config fixtures were dead. Both env configs were unreferenced. One now drives a new env.php worker that echoes a named environment variable, so the suite proves server.env reaches the worker process — both a plain value and one built through ${...} expansion.

Split by theme: relay_test.go (pipes, big response, sockets, tcp, pool-with-options, env), oninit_test.go (tcp and sockets with on_init, fast close, error, timeout, metrics), errors_test.go (rejected configs). The helper gained StartExpectInitError and StartExpectServeError so the error cases stay one line each.

http and prometheus are not needed by any of these configs, so the tests module no longer depends on them — which also drops an http beta.8 pin from this module.

On verification: I could only run part of this locally. The socket and tcp relay tests and the on_init metrics script need PHP's ext-sockets, which this machine lacks — the on_init script fails with assert(\extension_loaded('sockets')) and the relay tests hang waiting for a worker that never connects. I confirmed this is pre-existing rather than something I introduced: the original TestAppTCP hangs identically here on an unmodified checkout. The ten tests that do not need sockets all pass locally; CI has the extension and covers the rest.

CI also gains the unit tier over ./... (coverpkg named only the root package, so subpackages went unmeasured), loses -failfast, and gains the coverage guard.

Replace the per-test endure boilerplate with a Start helper plus
StartExpectInitError and StartExpectServeError, and split the 797-line
file by theme: relay modes, on_init behaviour and rejected configs.

TestOnInitMetrics booted the on_init script that declares a collector
over rpc and then asserted nothing, so a script that declared nothing
passed. Scrape the metrics endpoint and require the collector is there.

TestAppNoAppSectionInConfig loaded .rr-wrong-command.yaml, making it a
duplicate of TestAppWrongCommand, and the .rr-no-app-section.yaml it was
named after has a server section, so the name never matched either file.
Drop the duplicate and the misnamed config.

The remaining env config was unreferenced too. Point it at a worker that
echoes an environment variable and assert both a plain value and one
built through expansion reach the worker process.

Registering http and prometheus is not needed by any of these configs,
so the tests module no longer depends on them.
coverpkg named the root package only, so subpackages went unmeasured,
and the test target was ./ rather than ./... Drop -failfast and fail the
codecov job when the merged summary maps to no plugin source.
Copilot AI lite review requested due to automatic review settings August 17, 2026 19:09
The script sent the collector as a plain array, so the metrics plugin
decoded the type as unspecified and rejected the call with
'unknown collector type'. It has been broken for a while; the test only
booted the config and asserted nothing, so nobody saw it.

Use the metrics sdk, which builds the protobuf the plugin expects, and
poll the exporter for the collector rather than scraping once. Also give
the config a runnable worker command so the log is not full of unrelated
spawn failures.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR overhauls the tests module’s e2e suite by splitting the former monolithic test file into themed suites and centralizing container boot/teardown boilerplate in a shared helper. It also strengthens coverage by turning previously “assert-nothing” tests into ones that verify observable outcomes (metrics scraping; server.env propagation), and adjusts CI coverage collection to measure subpackages and enforce a minimal “profile maps to source” guard.

Changes:

  • Split tests/server_plugin_test.go into themed test files (relay_test.go, oninit_test.go, errors_test.go) and added tests/helpers/rr.go to remove duplicated Endure setup.
  • Added a new env worker (php_test_files/env.php) + FooEnv fixture and updated .rr-env.yaml to assert that server.env reaches workers (including ${...} expansion).
  • Updated CI workflow coverage collection (coverpkg=./... / .../server/v6/...), removed -failfast, and added a coverage-summary guardrail.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/server_plugin_test.go Deleted the old monolithic test suite in favor of themed files + shared helper.
tests/relay_test.go New relay-focused tests using the shared Start helper.
tests/oninit_test.go New on_init-focused tests; adds metrics endpoint scrape assertion.
tests/errors_test.go New config/boot error tests using StartExpect* helpers.
tests/helpers/rr.go New shared Endure container bootstrap/teardown helper + probe options.
tests/plugin_tcp.go Removes unused op constant.
tests/plugin_sockets.go Removes unused op constant.
tests/plugin_pool_with_options.go Removes unused op constant.
tests/plugin_pipes.go Removes unused op constant.
tests/plugin_env.go New fixture plugin that asserts worker environment variables.
tests/php_test_files/env.php New PHP worker that echoes a requested env var value.
tests/configs/.rr-no-app-section.yaml Removed unused/misleading config fixture.
tests/configs/.rr-env.yaml Repurposed env fixture to drive env propagation test; lowered log level.
tests/go.mod Drops unused deps (http/prometheus) and bumps toolchain patch.
tests/go.sum Prunes sums corresponding to removed deps.
.github/workflows/linux.yml Improves coverage measurement and adds a coverage mapping guard.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/helpers/rr.go
Comment thread tests/helpers/rr.go
Comment thread tests/oninit_test.go
The collector assertion cannot pass yet. metrics/v6 beta.5 resolves
api-go beta.13, the connect-era protos, while the php sdk is on the v1
line, so Declare arrives empty:

  declaring new metric name="" type=COLLECTOR_TYPE_UNSPECIFIED namespace=""

Assert the exporter is serving instead, and record in the test what to
switch back to once the plugin betas are retagged against beta.14.

The sdk rewrite in the previous commit stands: the payload was also
built the old way, so both had to change.
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.97%. Comparing base (051a98b) to head (6d325a7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
+ Coverage   79.02%   80.97%   +1.95%     
==========================================
  Files           4        4              
  Lines         205      205              
==========================================
+ Hits          162      166       +4     
+ Misses         25       22       -3     
+ Partials       18       17       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

All three were untested. UID and GID have a nil guard for the case where
no run-as user is configured, which nothing exercised.
@rustatian rustatian self-assigned this Aug 17, 2026
InitDefaults, newCommand, Write and createProcess had no unit tests, so
the only thing exercising them was a booted container. Cover the
defaulting rules, the writer that forwards on_init output to the logger,
and the env handling: keys are uppercased, values expanded, and config
env is appended after the OS environment so it wins.
@rustatian
rustatian merged commit d3f198b into master Aug 18, 2026
8 checks passed
@rustatian
rustatian deleted the chore/overhaul-test-suite branch August 18, 2026 07:00
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