@@ -63,31 +63,30 @@ func StartTest(t *testing.T, opts ...Option) *Test {
6363func StartTestFromCaller (t * testing.T , pc uintptr , opts ... Option ) * Test {
6464
6565 // check if the test is cached
66- if isTestCached (t , pc ) {
67-
68- test := & Test {t : t , ctx : context .Background ()}
69- for _ , opt := range opts {
70- opt (test )
71- }
72-
73- // Extracting the testing func name (by removing any possible sub-test suffix `{test_func}/{sub_test}`)
74- // to search the func source code bounds and to calculate the package name.
75- fullTestName := runner .GetOriginalTestName (t .Name ())
76- pName , _ := instrumentation .GetPackageAndName (pc )
77-
78- testTags := opentracing.Tags {
79- "span.kind" : "test" ,
80- "test.name" : fullTestName ,
81- "test.suite" : pName ,
82- "test.framework" : "testing" ,
83- "test.language" : "go" ,
66+ if ok , testsDescription := isTestCached (t , pc ); ok {
67+ ctx := context .Background ()
68+ tracer := instrumentation .Tracer ()
69+ for _ , desc := range testsDescription {
70+ startTime := time .Now ()
71+ options := []opentracing.StartSpanOption {
72+ opentracing.Tags {
73+ "span.kind" : "test" ,
74+ "test.name" : desc .Name ,
75+ "test.suite" : desc .Suite ,
76+ "test.framework" : "testing" ,
77+ "test.language" : "go" ,
78+ },
79+ opentracing .StartTime (startTime ),
80+ }
81+ span , _ := opentracing .StartSpanFromContextWithTracer (ctx , tracer , desc .Name , options ... )
82+ span .SetBaggageItem ("trace.kind" , "test" )
83+ span .SetTag ("test.status" , tags .TestStatus_CACHE )
84+ span .FinishWithOptions (opentracing.FinishOptions {
85+ FinishTime : startTime ,
86+ })
8487 }
85- span , _ := opentracing .StartSpanFromContextWithTracer (test .ctx , instrumentation .Tracer (), fullTestName , testTags )
86- span .SetBaggageItem ("trace.kind" , "test" )
87- span .SetTag ("test.status" , tags .TestStatus_CACHE )
88- span .Finish ()
8988 t .SkipNow ()
90- return test
89+ return nil
9190
9291 } else {
9392
@@ -320,16 +319,22 @@ func addAutoInstrumentedTest(t *testing.T) {
320319}
321320
322321// Get if the test is cached
323- func isTestCached (t * testing.T , pc uintptr ) bool {
324- pkgName , testName := instrumentation .GetPackageAndName (pc )
322+ func isTestCached (t * testing.T , pc uintptr ) (bool , []config.TestDescription ) {
323+ pkgName , _ := instrumentation .GetPackageAndName (pc )
324+ testName := runner .GetOriginalTestName (t .Name ())
325325 fqn := fmt .Sprintf ("%s.%s" , pkgName , testName )
326326 cachedMap := config .GetCachedTestsMap ()
327327 if _ , ok := cachedMap [fqn ]; ok {
328328 instrumentation .Logger ().Printf ("Test '%v' is cached." , fqn )
329- fmt .Print ("[SCOPE CACHED] " )
329+ var tests []config.TestDescription
330+ for _ , v := range cachedMap {
331+ if v .Suite == pkgName && strings .HasPrefix (v .Name , testName ) {
332+ tests = append (tests , v )
333+ }
334+ }
330335 reflection .SkipAndFinishTest (t )
331- return true
336+ return true , tests
332337 }
333338 instrumentation .Logger ().Printf ("Test '%v' is not cached." , fqn )
334- return false
339+ return false , nil
335340}
0 commit comments