This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This
PR
adds auto instrumentation to sub tests and sub benchmarks.The problem on auto instrumenting sub tests and sub benchmarks is that the call to
t.Run
andb.Run
are recursive from the initial test execution to other sub tests.An initial try to solve the problem could be the following implementation:
This uses
Patch
andUnpatch
twice to use the originalt.Run
implementation. The problem with this algorithm is that is not valid onParallel
scenarios, because we don't know the execution order, If we try to use amutex
we end with a deadlock, because eachfunc
executed byt.Run
runs in a separated goroutine.The way we solve to solve this issue, is by never
Unpatch
the patched function, but calling the original implementation in another way.In this case we copy the implementation of both
t.Run
andb.Run
from the original golang source code, to do that we are forced to create the sametesting.T
andtesting.B
structure and useunsafe
to have access to the private fields and use somelinking
to private methods. Note with this implementation we don't need any lock.With this, we add auto instrumentation support for the following cases:
Tests
Benchmarks