Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
9 changes: 9 additions & 0 deletions instrumentation/testing/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func initCoverage() {
func startCoverage() {
countersMutex.Lock()
defer countersMutex.Unlock()
if cover.Mode == "" {
return
}
initCoverage()

for name, counts := range cover.Counters {
Expand All @@ -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]))
Expand All @@ -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 {
Expand Down
15 changes: 8 additions & 7 deletions instrumentation/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +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 {
cov := endCoverage()
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 {
Expand Down