From 92c170fea5bba22ee979bb163abf7eadc5c6b9d0 Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Tue, 25 Feb 2020 17:04:31 +0100 Subject: [PATCH] Disable `t.Parallel` with env vars in the auto instrumentation --- autoinstrument/init.go | 13 +++++++++++++ env/vars.go | 1 + 2 files changed, 14 insertions(+) diff --git a/autoinstrument/init.go b/autoinstrument/init.go index d76e4b7f..bec4614c 100644 --- a/autoinstrument/init.go +++ b/autoinstrument/init.go @@ -8,6 +8,7 @@ import ( "github.com/undefinedlabs/go-mpatch" "go.undefinedlabs.com/scopeagent" + "go.undefinedlabs.com/scopeagent/env" "go.undefinedlabs.com/scopeagent/instrumentation" scopetesting "go.undefinedlabs.com/scopeagent/instrumentation/testing" ) @@ -38,6 +39,18 @@ func init() { return scopeagent.Run(m) }) logOnError(err) + + if !env.ScopeTestingDisableParallel.Value { + return + } + var t *testing.T + var tParallelMethod reflect.Method + tType := reflect.TypeOf(t) + if tParallelMethod, ok = tType.MethodByName("Parallel"); !ok { + return + } + _, err = mpatch.PatchMethodByReflect(tParallelMethod, func(t *testing.T) {}) + logOnError(err) }) } diff --git a/env/vars.go b/env/vars.go index 2b202cb6..db61d58c 100644 --- a/env/vars.go +++ b/env/vars.go @@ -17,6 +17,7 @@ var ( ScopeTestingMode = newBooleanEnvVar(false, "SCOPE_TESTING_MODE") ScopeTestingFailRetries = newIntEnvVar(0, "SCOPE_TESTING_FAIL_RETRIES") ScopeTestingPanicAsFail = newBooleanEnvVar(false, "SCOPE_TESTING_PANIC_AS_FAIL") + ScopeTestingDisableParallel = newBooleanEnvVar(false, "SCOPE_TESTING_DISABLE_PARALLEL") ScopeConfiguration = newSliceEnvVar([]string{tags.PlatformName, tags.PlatformArchitecture, tags.GoVersion}, "SCOPE_CONFIGURATION") ScopeMetadata = newMapEnvVar(nil, "SCOPE_METADATA") ScopeInstrumentationHttpPayloads = newBooleanEnvVar(false, "SCOPE_INSTRUMENTATION_HTTP_PAYLOADS")