Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1649 WebViewTracking integration test added #714

Merged

Conversation

buranmert
Copy link
Contributor

@buranmert buranmert commented Jan 11, 2022

What and why?

Adding integration test to WebView tracking feature.

How?

In this new test, the app opens a WebView which loads Browser SDK instrumented content. The iOS SDK should transport all RUM events and Logs received from Browser SDK.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference

@buranmert buranmert requested a review from a team as a code owner January 11, 2022 13:55
@buranmert buranmert self-assigned this Jan 11, 2022
@buranmert buranmert force-pushed the buranmert/RUMM-1649-integration-tests branch from 20b2f5d to 27b27ea Compare January 12, 2022 11:09
@buranmert buranmert marked this pull request as draft January 13, 2022 13:48
@buranmert buranmert force-pushed the buranmert/RUMM-1649-integration-tests branch from 27b27ea to 85b4528 Compare January 14, 2022 15:56
@buranmert buranmert marked this pull request as ready for review January 14, 2022 15:57
@buranmert
Copy link
Contributor Author

Most of the changes coming from the merge from master in order to get the new source property

@buranmert buranmert force-pushed the buranmert/RUMM-1649-integration-tests branch from 85b4528 to 048ee6b Compare January 14, 2022 16:08
WebViewScenarioTest uses an actual website to test WebView Tracking feature
@buranmert buranmert force-pushed the buranmert/RUMM-1649-integration-tests branch from 048ee6b to 1d95970 Compare January 14, 2022 16:39
@ncreated ncreated assigned ncreated and unassigned buranmert Jan 17, 2022
@ncreated ncreated changed the base branch from feature/hybrid-application to ncreated/RUMM-1649-update-hybrid-apps-with-master January 17, 2022 08:28
@ncreated
Copy link
Member

Most of the changes coming from the merge from master in order to get the new source property

I isolated updating hybrid-application with master to #722 to keep this PR minimal.

…ng test plan

this is done by switching crash reporting `.xctestplan` to not include new tests automatically
and removing Webviews test from the existing list.
@ncreated ncreated marked this pull request as draft January 17, 2022 08:53
Base automatically changed from ncreated/RUMM-1649-update-hybrid-apps-with-master to feature/hybrid-application January 17, 2022 10:15
Comment on lines -36 to +38
"skippedTests" : [
"IntegrationTests",
"LoggingScenarioTests",
"RUMManualInstrumentationScenarioTests",
"RUMMobileVitalsScenarioTests",
"RUMModalViewsScenarioTests",
"RUMNavigationControllerScenarioTests",
"RUMResourcesScenarioTests",
"RUMScrubbingScenarioTests",
"RUMSwiftUIScenarioTests",
"RUMTabBarControllerScenarioTests",
"RUMTapActionScenarioTests",
"TracingManualInstrumentationScenarioTests",
"TracingURLSessionScenarioTests",
"TrackingConsentScenarioTests"
"selectedTests" : [
"CrashReportingWithLoggingScenarioTests\/testCrashReportingCollectOrSendWithLoggingScenario()",
"CrashReportingWithRUMScenarioTests\/testCrashReportingCollectOrSendWithRUMScenario()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is on purpose. By default, all new integration tests are added to both XCTest plans (integration and crash reporting), meaning we will run it twice on CI. To avoid this, I disabled "add new tests automatically" in crash reporting XCTest plan. Apparently, this means changing from opt-out to opt-in in .xctestplan 👍.

@ncreated ncreated force-pushed the buranmert/RUMM-1649-integration-tests branch from 85da275 to 6c260e5 Compare January 17, 2022 11:27
@ncreated
Copy link
Member

I added more assertions on data received from Browser SDK, this includes checks like:

  • if Browser events are sent to native iOS RUM session (using native application_id and session_id);
  • if Browser logs are transported through iOS SDK;
  • if Browser logs are correlated with native iOS RUM session.

@ncreated ncreated marked this pull request as ready for review January 17, 2022 11:30
@ncreated ncreated requested a review from maxep January 17, 2022 11:30
Comment on lines 46 to 52
if let eventType = json["type"] as? String,
eventType == "resource",
var resource = json["resource"] as? [String: Any],
let method = resource["method"] as? String {
resource["method"] = method.uppercased()
json["resource"] = resource
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do case-insensitive comparison instead of transforming the payload?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if we want to keep using RUMEventMatcher. This matcher decodes certain RUM event model from Data:

func model<DM: Decodable>(file: StaticString = #file, line: UInt = #line) throws -> DM

RUM events schema defines uppercased values for resource.method:

"method": {
   "type": "string",
   "description": "HTTP method of the resource",
   "enum": ["POST", "GET", "HEAD", "PUT", "DELETE", "PATCH"],
   "readOnly": true
},

Because our RUMDataModels definition is strict about this and Browser SDK seems not, receiving lowercased method name from WebView (e.g. "get" instead of "GET") leads to decoding error. IMO this is an inconsistency in Browser SDK and we need to patch it in order to leverage strict validation with RUMEventMatcher and RUMSessionMatcher in our tests.

However, I think we can move this patch to a better place. Residing here in RUMEventMatcher, it is applied globally to all our test data, but the only problematic test is WebViewScenarioTest.swift where we consume real Browser SDK events. I'd vote for transforming data directly in WebViewScenarioTest.swift before passing it to the matcher, as this will minimalize the impact of this patch and be more explanatory. WDYT on this @maxep ?

Alternatively, we could resign from using strict matchers and assert all values as [String: Any] on events deserialized with JSONSerialization. This way we can perform case-insensitive comparison, but we lose all other strict validation from RUMSessionMatcher. Adding this validation back would require bloating WebViewScenarioTest.swift with manual deserialization code and duplication of all validation concepts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree! it would be better to move it where the transformation is needed. It clarify that we relax the rule for this specific use case only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to WebViewScenarioTest.swift ✅. I also talked with browser-sdk team - they will fix it in future release.

Such fix is required, as some queries in hybrid apps (e.g. count all resources by resource.method) might be giving odd results (i.e. considering "post" and "POST" as separate methods).

Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@ncreated ncreated merged commit 8636d3b into feature/hybrid-application Jan 18, 2022
@ncreated ncreated deleted the buranmert/RUMM-1649-integration-tests branch January 18, 2022 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants