[test-improver] Improve tests for sys package#7848
Conversation
- Add t.Parallel() to TestExtractContainerIDFromContent and all subtests - Add t.Parallel() to TestContainsAny_Helper and all subtests - Add t.Parallel() to all TestExtractContainerIDFromCgroupFiles_* tests - Add scanner-overflow test case (bufio.MaxScanTokenSize+1 line) to cover the scanner.Err() != nil path in extractContainerIDFromContent Coverage: internal/sys 98.9% -> 100.0% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the internal/sys test suite by adding explicit coverage for an edge-case error path in container ID parsing and by enabling parallel execution for tests that are safe to run concurrently. This helps keep the sys package’s tests more robust while reducing overall test wall-clock time.
Changes:
- Added a new test case to exercise the
bufio.Scanneroverflow/error branch inextractContainerIDFromContent. - Marked pure-function / temp-file-only tests as parallelizable via
t.Parallel()(including table subtests).
Show a summary per file
| File | Description |
|---|---|
| internal/sys/container_test.go | Adds scanner-overflow test case for extractContainerIDFromContent and parallelizes pure-function table tests. |
| internal/sys/container_detect_test.go | Parallelizes temp-file-only tests for extractContainerIDFromCgroupFiles to reduce runtime without changing behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
Fixed in e871e13. I removed duplicate TLS declarations/tests ( |
Test Improvements:
internal/sys/container_test.go+container_detect_test.goFile Analyzed
internal/sys/container_test.go,internal/sys/container_detect_test.gointernal/sysImprovements Made
1. Scanner-overflow coverage (new test case)
Added a test case
"single line exceeding scanner buffer limit returns empty string"toTestExtractContainerIDFromContent. This covers the previously-untestedscanner.Err() != nilbranch inextractContainerIDFromContent(triggered when a single line exceedsbufio.MaxScanTokenSize= 65,536 bytes):{ name: "single line exceeding scanner buffer limit returns empty string", input: strings.Repeat("x", bufio.MaxScanTokenSize+1), want: "", },2. Parallel test execution
Added
t.Parallel()to all pure-function tests (safe to run concurrently — no environment mutation, no shared state):TestExtractContainerIDFromContent+ all 16 subtestsTestContainsAny_Helper+ all subtestsTestExtractContainerIDFromCgroupFiles_*tests incontainer_detect_test.go(temp-file only, not.Setenv)3. Increased Coverage
extractContainerIDFromContent→ 92.3%, package total → 98.9%extractContainerIDFromContent→ 100.0%, package total → 100.0%Test Execution
All tests pass with
-raceflag enabled. Tests run multiple times with consistent results.Why These Changes?
extractContainerIDFromContentusedbufio.Scannerto parse cgroup content but the error path (scanner.Err() != nil) was never exercised — it requires a line longer than 64 KiB, an unusual but valid edge case. Adding the overflow test ensures the error path is verified. The parallelism additions are low-risk improvements to pure-function tests, reducing wall-clock test time with no behavior changes.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests