Skip to content

Conversation

@lmarceau
Copy link
Contributor

@lmarceau lmarceau commented Oct 3, 2025

📜 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

Screenshot 2025-09-26 at 11 23 09 AM Screenshot 2025-09-26 at 12 46 27 PM Screenshot 2025-10-03 at 12 53 56 PM

Opinions

  • I think we shouldn't call TelemetryWrapper events 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 guarantee Glean is setup for testing when we call those events, so I am adding a hasTelemetryOverride for unit testing purpose.
  • Flaky tests are worst than no tests, so I am disabling some unit tests in this PR and want to create follow up tasks so we either use MockGleanWrapper or other mocking mechanism in place to avoid calling Glean directly.
  • I am adding someXCTestCase extensions to help setup and teardown telemetry
  • With those changes we have 1 runtime only warning left when running unit tests
  • Modified testEventMetricRecordingSuccess so it's using an XCTUnwrap instead of force-unwrapping which meant a bunch of change in many files

📝 Checklist

  • I filled in the ticket numbers and a description of my work
  • I updated the PR name to follow our PR naming guidelines
  • I ensured unit tests pass and wrote tests for new code
  • If working on UI, I checked and implemented accessibility (Dynamic Text and VoiceOver)
  • If adding telemetry, I read the data stewardship requirements and will request a data review
  • If adding or modifying strings, I read the guidelines and will request a string review from l10n
  • If needed, I updated documentation and added comments to complex code

@mobiletest-ci-bot
Copy link

mobiletest-ci-bot commented Oct 3, 2025

Messages
📖 Project coverage: 39.03%

💪 Quality guardian

21 tests files modified. You're a champion of test coverage! 🚀

🧩 Neat Piece

This PR changes 601 lines. It's a substantial update,
but still review-friendly if there’s a clear description. Thanks for keeping things moving! 🚀

💬 Description craftsman

Great PR description! Reviewers salute you 🫡

✅ Per-file coverage

All changed files meet the threshold of 35.0%.

Client.app: Coverage: 37.21

File Coverage
PingUploaderProtocol.swift 100.0%
TelemetryWrapper.swift 64.38%
GleanHttpUploader.swift 95.16%

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing typo

Comment on lines -37 to -49
// 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

Copy link
Contributor Author

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:

Screenshot 2025-09-26 at 11 23 09 AM

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.

Comment on lines 19 to 20
Glean.shared.registerPings(GleanMetrics.Pings.shared)
Glean.shared.resetGlean(clearStores: true)
Copy link
Contributor

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

Copy link
Contributor Author

@lmarceau lmarceau Oct 3, 2025

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

Copy link
Contributor

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 🙏

@lmarceau lmarceau marked this pull request as ready for review October 3, 2025 18:53
@lmarceau lmarceau requested a review from a team as a code owner October 3, 2025 18:53
@lmarceau lmarceau requested review from Foxbolts, cyndichin and yoanarios and removed request for Foxbolts October 3, 2025 18:53
@testable import Client
import MozillaAppServices

// TODO: FXIOS-13565 - Migrate GleanPlumbMessageManagerTests to use mock telemetry or GleanWrapper
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@yoanarios yoanarios left a 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

@mergify
Copy link
Contributor

mergify bot commented Oct 7, 2025

This pull request has conflicts when rebasing. Could you fix it @lmarceau? 🙏

Copy link
Contributor

@cyndichin cyndichin left a 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!

@lmarceau lmarceau merged commit 769c467 into main Oct 8, 2025
9 checks passed
@lmarceau lmarceau deleted the lm/fix-telemetry branch October 8, 2025 13:35
@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2025

🚀 PR merged to main, targeting version: 144.1

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.

5 participants