-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Derek Nola <[email protected]>
- Loading branch information
Showing
4 changed files
with
44 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build cover | ||
|
||
package server | ||
|
||
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) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !cover | ||
|
||
package server | ||
|
||
import "context" | ||
|
||
func writeCoverage(ctx context.Context) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters