mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
b0188f5a13
* 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>
33 lines
705 B
Go
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|