golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.21k stars 17.7k forks source link

cmd/cover: spurious 0 line in coverprofile output #70441

Closed ct1n closed 2 days ago

ct1n commented 2 days ago

Go version

go1.22.9 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.9'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/build/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1442515923=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Running test coverage using a docker golang:1.22-alpine3.19 container. We run the following command:

go test -v -parallel 24 -p 24 -count 1 -covermode=atomic -coverprofile /coverage/coverage.out --timeout 30s ./...

What did you see happen?

The go test command sometimes generates either a line containing just the digit 0 at the end of coverage.out, or an empty line (though this seems rarer and I haven't checked that it's at the end of the file).

Trying to parse coverage.out with github.com/AlekSi/gocov-xml results in error: line "0" doesn't match expected format: couldn't find a before Count (from golang.org/x/tools.cover).

Other than the last line coverage.out seems valid: it starts with mode: atomic and contains about 15k report lines.

Not very easy to reproduce.

What did you expect to see?

A valid coverage.out profile that can be loaded by golang.org/x/tools/cover.

We can work around this pretty easily, but thought it might be useful in case others encounter this. Also it might be an easy fix.

gabyhelp commented 2 days ago

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

seankhliao commented 2 days ago

I think we need some form of reproducer

ct1n commented 2 days ago

Sorry for the noise. It seems this was because of our build process. Sometimes 2 builds ran at the same time and they weren't properly isolated, using the same output directory

ianlancetaylor commented 2 days ago

Thanks for following up.