Issue with integration test coverage

226 views
Skip to first unread message

savita juyal

unread,
Jul 11, 2023, 9:17:18 AM7/11/23
to golang-nuts
Hello All,

I am trying to collect integration test coverage but its not generating covcounters file. Please looks steps I am following to generate covearge.

- Build go binary : go build -race -cover -o $(ROOT)/go/bin/appwithrace -ldflags "-X app/handler.proxyVersion=$(VERSION) -X app/handler.gitVersion=$(GITVERSION) -X app/handler.buildTime=$(BUILDTIME)" cmd/proxy/proxy.go

- Run go binary : ENABLE_TLS=false ENABLE_TLS_TO_DB=false LOAD_BALANCED=false GOCOVERDIR=./coverage/int ./go/bin/appwithrace 2>&1 >/dev/null &

- Exit go program : Kill -9 go_process_id

Now we only covmetadata file generated under the given path. Please me know what I am doing wrong or if I am missing something?

Regards
Savita Juyal





Brian Candler

unread,
Jul 11, 2023, 9:48:57 AM7/11/23
to golang-nuts
Why are you using kill -9?  That doesn't allow the process any time to tidy up whilst exiting.


"If my program panics, will coverage data be written?

Programs built with go build -cover will only write out complete profile data at the end of execution if the program invokes os.Exit() or returns normally from main.main. If a program terminates in an unrecovered panic, or if the program hits a fatal exception (such as a segmentation violation, divide by zero, etc), profile data from statements executed during the run will be lost."


savita juyal

unread,
Jul 12, 2023, 8:18:31 AM7/12/23
to golang-nuts
Thank you so much Brian for helping me identify the problem. Now I am using kill -2 to pass SIGINT to the process, with this program is exiting politely and we are getting covcounter files. 

Regards
Savita Juyal

Chittoor Murari

unread,
Nov 7, 2024, 1:49:34 PMNov 7
to golang-nuts
I am facing the same issue.
I have go binary running in a docker container (built using -cover -covermode=atomic)
I am doing API testing by calling HTTP / grpc endpoints to the service (and comparing the response - an independent tool is doing this using curl / grpcurl)

I see that covmeta file is created, but when tests are running, covcounter are not generated.

Now, for graceful shutdown, I tried docker compose down - but this is not working.

Would someone be able to help?
Reply all
Reply to author
Forward
0 new messages