-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refactor FXIOS-13671 [Telemetry & Unit tests] Fix telemetry crashes in unit tests #29799
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
Conversation
💪 Quality guardian21 tests files modified. You're a champion of test coverage! 🚀 🧩 Neat PieceThis PR changes 601 lines. It's a substantial update, 💬 Description craftsmanGreat PR description! Reviewers salute you 🫡 ✅ Per-file coverageAll changed files meet the threshold of 35.0%. Client.app: Coverage: 37.21
Generated by 🚫 Danger Swift against 8ea301c |
| uploadTask.resume() | ||
| } else { | ||
| logger.log("Rejected ohttp ping since couldn't build request", level: .info, category: .telemetry) | ||
| logger.log("Rejected http ping since couldn't build request", level: .info, category: .telemetry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing typo
| // NOTE: We're using `URLSession.uploadTask` which ignores the `httpBody` and | ||
| // instead takes the body payload as a parameter to add to the request. | ||
| // However in tests we're using OHHTTPStubs to stub out the HTTP upload. | ||
| // It has the known limitation that it doesn't simulate data upload, | ||
| // because the underlying protocol doesn't expose a hook for that. | ||
| // By setting `httpBody` here the data is still attached to the request, | ||
| // so OHHTTPStubs sees it. | ||
| // It shouldn't be too bad memory-wise and not duplicate the data in memory. | ||
| // This should only be a reference and Swift keeps track of all the places it's needed. | ||
| // | ||
| // See https://github.com/AliSoftware/OHHTTPStubs#known-limitations. | ||
| request.httpBody = data | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added that as part of the PingUploader code since it was part of the Glean implemenation, but we don't use OHHTTPStubs so it makes no sense to use here.
This is part of why we see those runtime warnings when running unit tests:
But even removing that request.httpBody = data, I was still seeing hundreds of The request of a upload task runtime warnings, which made me realize we call Glean telemetry without having it setup for unit tests in some test suite.
| Glean.shared.registerPings(GleanMetrics.Pings.shared) | ||
| Glean.shared.resetGlean(clearStores: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have setupTelemetry here as well? But I have a PR that should address the microsurvey ones appropriately since @isabelrios pinged me about it., maybe we can merge that one instead of using this since that's the path forward we want to go with? #29814
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah for sure, your PR is the way to go for that particular test suite! We can merge mine after yours is merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! I merged it and yoana has an upcoming one for ShareTelemetryTests, but this PR looks good to merge after resolving any conflicts. Appreciate you making the tickets 🙏
| @testable import Client | ||
| import MozillaAppServices | ||
|
|
||
| // TODO: FXIOS-13565 - Migrate GleanPlumbMessageManagerTests to use mock telemetry or GleanWrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀, thanks for creating all the follow up tickets
|
This pull request has conflicts when rebasing. Could you fix it @lmarceau? 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @lmarceau for working on this and creating the tickets! looks good to me at high level, I haven't dived into the details, but feel free to merge when resolving conflicts since I trust @yoanarios approval!
2f68782 to
8ea301c
Compare
|
🚀 PR merged to |
📜 Tickets
Jira ticket
Github issue
💡 Description
Testing some ideas to fix telemetry crashing in unit tests. We have many (hundreds) of runtime warnings when unit tests are run. Some relates to Glean, some relates to Nimbus.
Examples
Opinions
TelemetryWrapperevents when we are unit testing, unless this is specifically wanted. My reasoning is we often call telemetry events as side-effect of unit testing some code. There's no guaranteeGleanis setup for testing when we call those events, so I am adding ahasTelemetryOverridefor unit testing purpose.MockGleanWrapperor other mocking mechanism in place to avoid callingGleandirectly.XCTestCaseextensions to help setup and teardown telemetrytestEventMetricRecordingSuccessso it's using anXCTUnwrapinstead of force-unwrapping which meant a bunch of change in many files📝 Checklist