k3s/pkg/cli/cmds/cover_linux.go
Derek Nola b0188f5a13
Test Coverage Reports for E2E tests (#7526)
* Move coverage writer into agent and server
* Add coverage report to E2E PR tests
* Add codecov upload to drone

Signed-off-by: Derek Nola <derek.nola@suse.com>
2023-06-05 14:15:17 -07:00

33 lines
705 B
Go

//go:build linux && cover
package cmds
import (
"context"
"os"
"runtime/coverage"
"time"
"github.com/sirupsen/logrus"
)
// writeCoverage checks if GOCOVERDIR is set on startup and writes coverage files to that directory
// every 20 seconds. This is done to ensure that the coverage files are written even if the process is killed.
func WriteCoverage(ctx context.Context) {
if k, ok := os.LookupEnv("GOCOVERDIR"); ok {
for {
select {
case <-ctx.Done():
if err := coverage.WriteCountersDir(k); err != nil {
logrus.Warn(err)
}
return
case <-time.After(20 * time.Second):
if err := coverage.WriteCountersDir(k); err != nil {
logrus.Warn(err)
}
}
}
}
}