Improve error behaviour of package coverage.

This commit is contained in:
Katharine Berry
2018-08-31 17:06:20 -07:00
parent facce197b1
commit 13d1961d2b
2 changed files with 12 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ package coverage
import (
"flag"
"fmt"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/wait"
"os"
@@ -29,8 +30,6 @@ import (
"time"
)
var flushInterval = 5 * time.Second
var coverageFile string
// tempCoveragePath returns a temporary file to write coverage information to.
@@ -48,9 +47,16 @@ func InitCoverage(name string) {
if coverageFile == "" {
coverageFile = "/tmp/k8s-" + name + ".cov"
}
fmt.Println("Dumping coverage information to " + coverageFile)
if duration, err := time.ParseDuration(os.Getenv("KUBE_COVERAGE_FLUSH_INTERVAL")); err == nil {
flushInterval = duration
flushInterval := 5 * time.Second
requestedInterval := os.Getenv("KUBE_COVERAGE_FLUSH_INTERVAL")
if requestedInterval != "" {
if duration, err := time.ParseDuration(requestedInterval); err == nil {
flushInterval = duration
} else {
panic("Invalid KUBE_COVERAGE_FLUSH_INTERVAL value; try something like '30s'.")
}
}
// Set up the unit test framework with the required arguments to activate test coverage.