Skip to content

Commit

Permalink
cli: flush coverage report in defer function
Browse files Browse the repository at this point in the history
Do not flush it atexit(), where the test report file might be already
closed and it causes go test failure like:

PASS
testing: can't write /tmp/go-build146132196/b001/testlog.txt: close /tmp/go-build146132196/b001/testlog.txt: file already closed
FAIL    github.com/kata-containers/runtime/cli  4.256s

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
  • Loading branch information
bergwolf committed Dec 26, 2019
1 parent f56d70c commit 3deb24e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ func TestMain(m *testing.M) {

// Make sure we have the opportunity to flush the coverage report to disk when
// terminating the process.
atexit(cover.FlushProfiles)
defer func() {
cover.FlushProfiles()
}()

// If the test binary name is kata-runtime.coverage, we've are being asked to
// run the coverage-instrumented kata-runtime.
Expand Down

0 comments on commit 3deb24e

Please sign in to comment.