diff --git a/instrumentation/testing/init.go b/instrumentation/testing/init.go index b3cb5ece..58cda8e6 100644 --- a/instrumentation/testing/init.go +++ b/instrumentation/testing/init.go @@ -1,14 +1,27 @@ package testing import ( + "flag" "reflect" "testing" + "go.undefinedlabs.com/scopeagent/instrumentation" "go.undefinedlabs.com/scopeagent/reflection" ) +var ( + parallel int +) + // Initialize the testing instrumentation func Init(m *testing.M) { + flag.Parse() + fPtr := flag.Lookup("test.parallel") + if fPtr != nil { + parallel = (*fPtr).Value.(flag.Getter).Get().(int) + instrumentation.Logger().Println("parallel flag set to:", parallel) + } + if tPointer, err := reflection.GetFieldPointerOf(m, "tests"); err == nil { intTests := (*[]testing.InternalTest)(tPointer) tests := make([]testing.InternalTest, 0) diff --git a/instrumentation/testing/testing.go b/instrumentation/testing/testing.go index 2692933d..54cc18b7 100644 --- a/instrumentation/testing/testing.go +++ b/instrumentation/testing/testing.go @@ -163,7 +163,7 @@ func (test *Test) end() { if testing.CoverMode() != "" { // Checks if the current test is running parallel to extract the coverage or not - if reflection.GetIsParallel(test.t) { + if reflection.GetIsParallel(test.t) && parallel > 1 { instrumentation.Logger().Printf("CodePath in parallel test is not supported: %v\n", test.t.Name()) restoreCoverageCounters() } else if cov := endCoverage(); cov != nil {