mirror of https://github.com/k3s-io/k3s
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
705 B
33 lines
705 B
1 year ago
|
//go:build linux && cover
|
||
2 years ago
|
|
||
1 year ago
|
package cmds
|
||
2 years ago
|
|
||
|
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.
|
||
1 year ago
|
func WriteCoverage(ctx context.Context) {
|
||
2 years ago
|
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)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|