From ece3d9ed389c86724c4cc49615c9c34b80292a5e Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Thu, 20 Feb 2020 10:16:16 +0100 Subject: [PATCH 1/2] coverage detection --- .github/workflows/go.yml | 2 +- instrumentation/testing/coverage.go | 9 +++++++++ instrumentation/testing/testing.go | 3 +-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3db14d27..f4db2147 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,7 +22,7 @@ jobs: run: go get -v -t -d ./... - name: Test - run: go test -v -race -covermode=atomic -coverprofile=cov ./... + run: go test -v -race -covermode=atomic ./... env: SCOPE_DSN: ${{ secrets.SCOPE_DSN }} diff --git a/instrumentation/testing/coverage.go b/instrumentation/testing/coverage.go index 9301d02e..40d679bd 100644 --- a/instrumentation/testing/coverage.go +++ b/instrumentation/testing/coverage.go @@ -83,6 +83,9 @@ func initCoverage() { func startCoverage() { countersMutex.Lock() defer countersMutex.Unlock() + if cover.Mode == "" { + return + } initCoverage() for name, counts := range cover.Counters { @@ -97,6 +100,9 @@ func startCoverage() { func restoreCoverageCounters() { countersMutex.Lock() defer countersMutex.Unlock() + if cover.Mode == "" { + return + } for name, counts := range cover.Counters { for i := range counts { atomic.StoreUint32(&counts[i], counters[name][i]+atomic.LoadUint32(&counts[i])) @@ -108,6 +114,9 @@ func restoreCoverageCounters() { func endCoverage() *coverage { countersMutex.Lock() defer countersMutex.Unlock() + if cover.Mode == "" { + return nil + } var covSource = map[string][]*blockWithCount{} for name, counts := range cover.Counters { diff --git a/instrumentation/testing/testing.go b/instrumentation/testing/testing.go index de156990..46e49aae 100644 --- a/instrumentation/testing/testing.go +++ b/instrumentation/testing/testing.go @@ -165,8 +165,7 @@ func (test *Test) end() { if reflection.GetIsParallel(test.t) { instrumentation.Logger().Printf("CodePath in parallel test is not supported: %v\n", test.t.Name()) restoreCoverageCounters() - } else { - cov := endCoverage() + } else if cov := endCoverage(); cov != nil { test.span.SetTag(tags.Coverage, *cov) } From 8627533bbbcc33531549d5cfdb88a795b8b78ba8 Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Thu, 20 Feb 2020 10:19:26 +0100 Subject: [PATCH 2/2] changes --- instrumentation/testing/testing.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/instrumentation/testing/testing.go b/instrumentation/testing/testing.go index 46e49aae..2692933d 100644 --- a/instrumentation/testing/testing.go +++ b/instrumentation/testing/testing.go @@ -161,12 +161,14 @@ func (test *Test) end() { LogRecords: logRecords, } - // Checks if the current test is running parallel to extract the coverage or not - if reflection.GetIsParallel(test.t) { - instrumentation.Logger().Printf("CodePath in parallel test is not supported: %v\n", test.t.Name()) - restoreCoverageCounters() - } else if cov := endCoverage(); cov != nil { - test.span.SetTag(tags.Coverage, *cov) + if testing.CoverMode() != "" { + // Checks if the current test is running parallel to extract the coverage or not + if reflection.GetIsParallel(test.t) { + instrumentation.Logger().Printf("CodePath in parallel test is not supported: %v\n", test.t.Name()) + restoreCoverageCounters() + } else if cov := endCoverage(); cov != nil { + test.span.SetTag(tags.Coverage, *cov) + } } if r := recover(); r != nil {