Skip to content

Commit 71cb481

Browse files
committed
fix: resolve coverage generation conflicts with stdio transport
Fix CI coverage generation failures caused by stdio transport test: Coverage Issue: - go test -coverprofile with ./... fails when tests capture stdout - TestRunWithTransport_Stdio uses stdio transport which takes over stdout - This conflicts with coverage output being written to stdout - Error: "write /dev/stdout: file already closed" Solutions Applied: 1. Skip stdio transport test when coverage is enabled (testing.CoverMode()) 2. Split coverage generation by package to avoid conflicts 3. Merge coverage files manually in CI workflow CI Workflow Changes: - Separate "Run tests" (race detector) from coverage generation - Generate coverage per package and merge into single file - Use atomic mode for accurate concurrent coverage Test Changes (transport_test.go): - Added coverage detection with testing.CoverMode() - Skip TestRunWithTransport_Stdio when coverage is enabled - Test still runs normally without coverage flag This allows full test coverage reporting while avoiding the stdout conflict. The stdio transport test is still run during normal testing and race detection, just skipped during coverage generation.
1 parent fd0c474 commit 71cb481

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ jobs:
5555
args: --timeout=3m
5656

5757
- name: Run tests
58+
run: go test -race ./...
59+
60+
- name: Generate coverage
5861
run: |
59-
go test -race ./...
60-
go test -coverprofile=coverage.out -covermode=atomic ./...
62+
echo 'mode: atomic' > coverage.out
63+
go test -coverprofile=coverage.tmp -covermode=atomic . && tail -n +2 coverage.tmp >> coverage.out || true
64+
go test -coverprofile=coverage.tmp -covermode=atomic ./cache && tail -n +2 coverage.tmp >> coverage.out || true
65+
go test -coverprofile=coverage.tmp -covermode=atomic ./httpx && tail -n +2 coverage.tmp >> coverage.out || true
66+
rm coverage.tmp
6167
6268
- name: Upload coverage report
6369
if: always()

transport_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ func TestRunWithTransport_Stdio(t *testing.T) {
2020
t.Fatalf("failed to create server: %v", err)
2121
}
2222

23+
// Skip actual transport test when running with coverage
24+
// because stdio transport captures stdout, breaking coverage output
25+
if testing.CoverMode() != "" {
26+
t.Skip("Skipping stdio transport test when coverage is enabled")
27+
}
28+
2329
// We can't actually run the server in a test (it would block),
2430
// but we can verify the function accepts the correct transport type
2531
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)