[No Jira][V3] Adapt internal-testing-tools-package to v3 (Android) #1079
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.
What does this PR do?
Same as we did with #1065, this PR changes the internal-testing-tool package logic to adapt to the changes done on v3 related to the SDK core instance and how to retrieve and wrap it to be able to capture the SDK events and successfully do E2E test runs on the nightly tests app.
Approach
The main problem relies on how v3 of the SDK works with the native SDK core. Before v3, the core was obtained during initialization and a reference to it was stored inside DatadogSDKWrapper. Then, every component of the React Native SDK would go through that reference to perform native SDK tasks. That has changed on v3, as that intermediate reference is now removed, and all modules rely directly on accessing
Datadog.getInstance()to directly obtain the SDK core.This works fine for the SDK on all fronts and it's a mandatory requirement to achieve SDK modularization. However, it causes a problem for the internal-testing-module, which relied on that core sdk reference to wrap the core around a StubSDKCore that would allow it to listen to SDK events and then assess if the SDK did what was asked of it properly.
The solution taken for the iOS SDK was simple, once the SDK is initialized we use the
onSdkInitializationlistenerto obtain the core, then wrap it with the testing and event listening code and then reassign it as the active core instance by using theregisterandunregistermethods exposed by the Datadog class.This was not that simple on Android, as those methods are internal, so the first hurdle to go over was to use reflection to access them. We encapsulated this core swap into a separate function, that also makes sure that the access to the core registry is synchronized, as otherwise it could cause concurrency problems when swapping the cores.
Next we did a few more changes to make sure that features are properly intercepted even if they are enabled before the internal testing module, as well as making sure that SDK calls are only performed once but it's calls are registered and written by the interceptors properly.
Motivation
We need to be able to use the Nightly Tests app to assess if new releases of the SDK are working properly or not.
Review checklist (to be filled by reviewers)