From e184d4cc7e6844be95119a1aa04227ce98e87815 Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Mon, 5 Dec 2022 14:00:06 +0100 Subject: [PATCH 1/9] fix: Remove SentrySystemEventBreadcrumbs observers with the most specific detail possible --- Sources/Sentry/SentrySystemEventBreadcrumbs.m | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentrySystemEventBreadcrumbs.m b/Sources/Sentry/SentrySystemEventBreadcrumbs.m index 6deb12d6d3..fa16ac80c5 100644 --- a/Sources/Sentry/SentrySystemEventBreadcrumbs.m +++ b/Sources/Sentry/SentrySystemEventBreadcrumbs.m @@ -41,11 +41,28 @@ - (void)start - (void)stop { #if TARGET_OS_IOS + // Remove the observers with the most specific detail possible, see + // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - [defaultCenter removeObserver:self]; + [defaultCenter removeObserver:self name:UIKeyboardDidShowNotification object:nil]; + [defaultCenter removeObserver:self name:UIKeyboardDidHideNotification object:nil]; + [defaultCenter removeObserver:self + name:UIApplicationUserDidTakeScreenshotNotification + object:nil]; + [defaultCenter removeObserver:self name:UIDeviceBatteryLevelDidChangeNotification object:nil]; + [defaultCenter removeObserver:self name:UIDeviceBatteryStateDidChangeNotification object:nil]; + [defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; + [defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; #endif } +- (void)dealloc +{ + // In dealloc it's safe to unsubscribe for all, see + // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver + [NSNotificationCenter.defaultCenter removeObserver:self]; +} + #if TARGET_OS_IOS /** * Only used for testing, call start() instead. From ae1ea17de5603151330b289dac001471f38835c4 Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Mon, 5 Dec 2022 14:04:52 +0100 Subject: [PATCH 2/9] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c409b721..11bd7179ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This version adds a dependency on Swift. - `SentryAppStateManager` correctly unsubscribes from `NSNotificationCenter` when closing the SDK (#2460) - The SDK no longer reports an OOM when a crash happens after closing the SDK (#2468) - Use the preexisting app release version format for profiles (#2470) +- Remove `SentrySystemEventBreadcrumbs` observers with the most specific detail possible (#2489) ### Breaking Changes From fe1afd74f548de97ba616d2618d4039a43f8bc1d Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Mon, 5 Dec 2022 19:08:10 +0100 Subject: [PATCH 3/9] Add test --- .../ImageProcessing/ColorArt.swift | 2 +- .../PerformanceViewController.swift | 2 +- .../SentryAutoBreadcrumbTrackingIntegration.m | 11 ++++---- Sources/Sentry/SentrySystemEventBreadcrumbs.m | 28 +++++++++++-------- .../include/SentrySystemEventBreadcrumbs.h | 5 +++- ...toBreadcrumbTrackingIntegrationTests.swift | 4 +-- .../SentrySystemEventBreadcrumbsTest.swift | 14 +++++++++- .../SentryAppStartTrackerTests.swift | 4 +-- .../SentryCrashScopeObserverTests.swift | 2 +- .../Networking/SentryHttpTransportTests.swift | 2 +- .../SentryCrashReportSinkTests.swift | 2 +- Tests/SentryTests/SentryScopeSwiftTests.swift | 2 +- 12 files changed, 50 insertions(+), 28 deletions(-) diff --git a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift index e59a410d2e..b0c6a7b2d8 100644 --- a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift +++ b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift @@ -319,7 +319,7 @@ private struct RGBADecimalComponents: Hashable { // Relative luminance formula: https://en.wikipedia.org/wiki/Relative_luminance var luminance: CGFloat { - 0.212_6 * r + 0.715_2 * g + 0.072_2 * b + 0.2126 * r + 0.7152 * g + 0.0722 * b } var isDarkColor: Bool { diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift index b4f81dd1a4..aaca80224b 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift @@ -37,7 +37,7 @@ class PerformanceViewController: UIViewController { // refresh rate of 60 hz is 0.0167 // 120 hz is 0.0083 // 240 hz is 0.004167 - private let interval = 0.000_000_05 + private let interval = 0.00000005 private var timer: Timer? private let iterations = 5_000_000 diff --git a/Sources/Sentry/SentryAutoBreadcrumbTrackingIntegration.m b/Sources/Sentry/SentryAutoBreadcrumbTrackingIntegration.m index eac0654cb5..22aa36c38b 100644 --- a/Sources/Sentry/SentryAutoBreadcrumbTrackingIntegration.m +++ b/Sources/Sentry/SentryAutoBreadcrumbTrackingIntegration.m @@ -29,11 +29,12 @@ - (BOOL)installWithOptions:(nonnull SentryOptions *)options breadcrumbTracker:[[SentryBreadcrumbTracker alloc] initWithSwizzleWrapper:[SentryDependencyContainer sharedInstance] .swizzleWrapper] - systemEventBreadcrumbs:[[SentrySystemEventBreadcrumbs alloc] - initWithFileManager:[SentryDependencyContainer sharedInstance] - .fileManager - andCurrentDateProvider:[SentryDefaultCurrentDateProvider - sharedInstance]]]; + systemEventBreadcrumbs: + [[SentrySystemEventBreadcrumbs alloc] + initWithFileManager:[SentryDependencyContainer sharedInstance].fileManager + andCurrentDateProvider:[SentryDefaultCurrentDateProvider sharedInstance] + andNotificationCenterWrapper:[SentryDependencyContainer sharedInstance] + .notificationCenterWrapper]]; return YES; } diff --git a/Sources/Sentry/SentrySystemEventBreadcrumbs.m b/Sources/Sentry/SentrySystemEventBreadcrumbs.m index fa16ac80c5..b65af0925b 100644 --- a/Sources/Sentry/SentrySystemEventBreadcrumbs.m +++ b/Sources/Sentry/SentrySystemEventBreadcrumbs.m @@ -3,6 +3,7 @@ #import "SentryCurrentDateProvider.h" #import "SentryDependencyContainer.h" #import "SentryLog.h" +#import "SentryNSNotificationCenterWrapper.h" #import "SentrySDK.h" // all those notifications are not available for tvOS @@ -14,16 +15,19 @@ SentrySystemEventBreadcrumbs () @property (nonatomic, strong) SentryFileManager *fileManager; @property (nonatomic, strong) id currentDateProvider; +@property (nonatomic, strong) SentryNSNotificationCenterWrapper *notificationCenterWrapper; @end @implementation SentrySystemEventBreadcrumbs - (instancetype)initWithFileManager:(SentryFileManager *)fileManager andCurrentDateProvider:(id)currentDateProvider + andNotificationCenterWrapper:(SentryNSNotificationCenterWrapper *)notificationCenterWrapper { if (self = [super init]) { _fileManager = fileManager; _currentDateProvider = currentDateProvider; + _notificationCenterWrapper = notificationCenterWrapper; } return self; } @@ -43,16 +47,18 @@ - (void)stop #if TARGET_OS_IOS // Remove the observers with the most specific detail possible, see // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver - NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - [defaultCenter removeObserver:self name:UIKeyboardDidShowNotification object:nil]; - [defaultCenter removeObserver:self name:UIKeyboardDidHideNotification object:nil]; - [defaultCenter removeObserver:self - name:UIApplicationUserDidTakeScreenshotNotification - object:nil]; - [defaultCenter removeObserver:self name:UIDeviceBatteryLevelDidChangeNotification object:nil]; - [defaultCenter removeObserver:self name:UIDeviceBatteryStateDidChangeNotification object:nil]; - [defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; - [defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; + [self.notificationCenterWrapper removeObserver:self name:UIKeyboardDidShowNotification]; + [self.notificationCenterWrapper removeObserver:self name:UIKeyboardDidHideNotification]; + [self.notificationCenterWrapper removeObserver:self + name:UIApplicationUserDidTakeScreenshotNotification]; + [self.notificationCenterWrapper removeObserver:self + name:UIDeviceBatteryLevelDidChangeNotification]; + [self.notificationCenterWrapper removeObserver:self + name:UIDeviceBatteryStateDidChangeNotification]; + [self.notificationCenterWrapper removeObserver:self + name:UIDeviceOrientationDidChangeNotification]; + [self.notificationCenterWrapper removeObserver:self + name:UIDeviceOrientationDidChangeNotification]; #endif } @@ -60,7 +66,7 @@ - (void)dealloc { // In dealloc it's safe to unsubscribe for all, see // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver - [NSNotificationCenter.defaultCenter removeObserver:self]; + [self.notificationCenterWrapper removeObserver:self]; } #if TARGET_OS_IOS diff --git a/Sources/Sentry/include/SentrySystemEventBreadcrumbs.h b/Sources/Sentry/include/SentrySystemEventBreadcrumbs.h index 57d079848e..d45241677c 100644 --- a/Sources/Sentry/include/SentrySystemEventBreadcrumbs.h +++ b/Sources/Sentry/include/SentrySystemEventBreadcrumbs.h @@ -6,11 +6,14 @@ # import #endif +@class SentryNSNotificationCenterWrapper; + @interface SentrySystemEventBreadcrumbs : NSObject SENTRY_NO_INIT - (instancetype)initWithFileManager:(SentryFileManager *)fileManager - andCurrentDateProvider:(id)currentDateProvider; + andCurrentDateProvider:(id)currentDateProvider + andNotificationCenterWrapper:(SentryNSNotificationCenterWrapper *)notificationCenterWrapper; - (void)start; diff --git a/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift b/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift index 764569b60b..b21581cb9e 100644 --- a/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift @@ -26,7 +26,7 @@ class SentryAutoBreadcrumbTrackingIntegrationTests: XCTestCase { func testInstallWithSwizzleEnabled_StartSwizzleCalled() { let sut = fixture.sut - sut.install(with: Options(), breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance())) + sut.install(with: Options(), breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance(), andNotificationCenterWrapper: TestNSNotificationCenterWrapper())) XCTAssertEqual(1, fixture.tracker.startInvocations.count) XCTAssertEqual(1, fixture.tracker.startSwizzleInvocations.count) @@ -37,7 +37,7 @@ class SentryAutoBreadcrumbTrackingIntegrationTests: XCTestCase { let options = Options() options.enableSwizzling = false - sut.install(with: options, breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance())) + sut.install(with: options, breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance(), andNotificationCenterWrapper: TestNSNotificationCenterWrapper())) XCTAssertEqual(1, fixture.tracker.startInvocations.count) XCTAssertEqual(0, fixture.tracker.startSwizzleInvocations.count) diff --git a/Tests/SentryTests/Integrations/Breadcrumbs/SentrySystemEventBreadcrumbsTest.swift b/Tests/SentryTests/Integrations/Breadcrumbs/SentrySystemEventBreadcrumbsTest.swift index 553c6bd5be..7679603ccb 100644 --- a/Tests/SentryTests/Integrations/Breadcrumbs/SentrySystemEventBreadcrumbsTest.swift +++ b/Tests/SentryTests/Integrations/Breadcrumbs/SentrySystemEventBreadcrumbsTest.swift @@ -10,6 +10,7 @@ class SentrySystemEventBreadcrumbsTest: XCTestCase { let options: Options let fileManager: TestFileManager var currentDateProvider = TestCurrentDateProvider() + let notificationCenterWrapper = TestNSNotificationCenterWrapper() init() { options = Options() @@ -26,7 +27,11 @@ class SentrySystemEventBreadcrumbsTest: XCTestCase { let hub = SentryHub(client: client, andScope: scope) SentrySDK.setCurrentHub(hub) - let systemEvents = SentrySystemEventBreadcrumbs(fileManager: fileManager, andCurrentDateProvider: currentDateProvider)! + let systemEvents = SentrySystemEventBreadcrumbs( + fileManager: fileManager, + andCurrentDateProvider: currentDateProvider, + andNotificationCenterWrapper: notificationCenterWrapper + )! systemEvents.start(currentDevice) return systemEvents } @@ -266,6 +271,13 @@ class SentrySystemEventBreadcrumbsTest: XCTestCase { } } + func testStopCallsSpecificRemoveObserverMethods() { + let scope = Scope() + sut = fixture.getSut(scope: scope, currentDevice: nil) + sut.stop() + XCTAssertEqual(fixture.notificationCenterWrapper.removeObserverWithNameInvocations.count, 7) + } + private func assertBreadcrumbAction(scope: Scope, action: String, checks: (([String: Any]) -> Void)? = nil) { let ser = scope.serialize() if let breadcrumbs = ser["breadcrumbs"] as? [[String: Any]] { diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift index 21557232de..d64d034fbc 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift @@ -397,7 +397,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { let expectedAppStartDuration = expectedDuration ?? fixture.appStartDuration let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.000_1) + XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.0001) if preWarmed { XCTAssertEqual(fixture.moduleInitializationTimestamp, appStartMeasurement.appStartTimestamp) @@ -420,7 +420,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { XCTAssertEqual(type.rawValue, appStartMeasurement.type.rawValue) let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.000_1) + XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.0001) XCTAssertEqual(fixture.sysctl.processStartTimestamp, appStartMeasurement.appStartTimestamp) XCTAssertEqual(fixture.runtimeInitTimestamp, appStartMeasurement.runtimeInitTimestamp) diff --git a/Tests/SentryTests/Integrations/SentryCrash/SentryCrashScopeObserverTests.swift b/Tests/SentryTests/Integrations/SentryCrash/SentryCrashScopeObserverTests.swift index 79442d79a4..7e670a61bb 100644 --- a/Tests/SentryTests/Integrations/SentryCrash/SentryCrashScopeObserverTests.swift +++ b/Tests/SentryTests/Integrations/SentryCrash/SentryCrashScopeObserverTests.swift @@ -297,7 +297,7 @@ class SentryCrashScopeObserverTests: XCTestCase { return jsonPointer!.pointee } - private func getScopeJson(getField: (SentryCrashScope)-> UnsafeMutablePointer?) -> String? { + private func getScopeJson(getField: (SentryCrashScope) -> UnsafeMutablePointer?) -> String? { guard let scopePointer = sentrycrash_scopesync_getScope() else { return nil } diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 40a8a6090e..4d1042197c 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -528,7 +528,7 @@ class SentryHttpTransportTests: XCTestCase { func testSendEnvelopesConcurrent() { self.measure { - fixture.requestManager.responseDelay = 0.000_1 + fixture.requestManager.responseDelay = 0.0001 let queue = fixture.queue diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 211c841f90..0bfbe70368 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -89,7 +89,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { } func testAppStartCrash_DurationTooBig_DoesNotCallFlush() { - fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.000_01 + fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.00001 filterReportWithAttachment() diff --git a/Tests/SentryTests/SentryScopeSwiftTests.swift b/Tests/SentryTests/SentryScopeSwiftTests.swift index 7327ee45dd..89ef6fc129 100644 --- a/Tests/SentryTests/SentryScopeSwiftTests.swift +++ b/Tests/SentryTests/SentryScopeSwiftTests.swift @@ -221,7 +221,7 @@ class SentryScopeSwiftTests: XCTestCase { func testUseSpanForClear() { fixture.scope.span = fixture.transaction - fixture.scope.useSpan { (span) in + fixture.scope.useSpan { (_) in self.fixture.scope.span = nil } XCTAssertNil(fixture.scope.span) From 257d1e8a854e6e256a3362554ef80fe6f5be2363 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Mon, 5 Dec 2022 18:09:38 +0000 Subject: [PATCH 4/9] Format code --- .../TrendingMovies/ImageProcessing/ColorArt.swift | 2 +- .../iOS-Swift/ViewControllers/PerformanceViewController.swift | 2 +- .../AppStartTracking/SentryAppStartTrackerTests.swift | 4 ++-- Tests/SentryTests/Networking/SentryHttpTransportTests.swift | 2 +- .../SentryTests/SentryCrash/SentryCrashReportSinkTests.swift | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift index b0c6a7b2d8..e59a410d2e 100644 --- a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift +++ b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift @@ -319,7 +319,7 @@ private struct RGBADecimalComponents: Hashable { // Relative luminance formula: https://en.wikipedia.org/wiki/Relative_luminance var luminance: CGFloat { - 0.2126 * r + 0.7152 * g + 0.0722 * b + 0.212_6 * r + 0.715_2 * g + 0.072_2 * b } var isDarkColor: Bool { diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift index aaca80224b..b4f81dd1a4 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift @@ -37,7 +37,7 @@ class PerformanceViewController: UIViewController { // refresh rate of 60 hz is 0.0167 // 120 hz is 0.0083 // 240 hz is 0.004167 - private let interval = 0.00000005 + private let interval = 0.000_000_05 private var timer: Timer? private let iterations = 5_000_000 diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift index d64d034fbc..21557232de 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift @@ -397,7 +397,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { let expectedAppStartDuration = expectedDuration ?? fixture.appStartDuration let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.0001) + XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.000_1) if preWarmed { XCTAssertEqual(fixture.moduleInitializationTimestamp, appStartMeasurement.appStartTimestamp) @@ -420,7 +420,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { XCTAssertEqual(type.rawValue, appStartMeasurement.type.rawValue) let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.0001) + XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.000_1) XCTAssertEqual(fixture.sysctl.processStartTimestamp, appStartMeasurement.appStartTimestamp) XCTAssertEqual(fixture.runtimeInitTimestamp, appStartMeasurement.runtimeInitTimestamp) diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 4d1042197c..40a8a6090e 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -528,7 +528,7 @@ class SentryHttpTransportTests: XCTestCase { func testSendEnvelopesConcurrent() { self.measure { - fixture.requestManager.responseDelay = 0.0001 + fixture.requestManager.responseDelay = 0.000_1 let queue = fixture.queue diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 0bfbe70368..211c841f90 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -89,7 +89,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { } func testAppStartCrash_DurationTooBig_DoesNotCallFlush() { - fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.00001 + fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.000_01 filterReportWithAttachment() From 0f5b1f5426fa2e365dcb62328e40fa2faceceec0 Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Mon, 5 Dec 2022 20:57:47 +0100 Subject: [PATCH 5/9] Apply suggestions from code review --- .../SentryAutoBreadcrumbTrackingIntegrationTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift b/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift index b21581cb9e..64ba0f61b6 100644 --- a/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/Breadcrumbs/SentryAutoBreadcrumbTrackingIntegrationTests.swift @@ -26,7 +26,7 @@ class SentryAutoBreadcrumbTrackingIntegrationTests: XCTestCase { func testInstallWithSwizzleEnabled_StartSwizzleCalled() { let sut = fixture.sut - sut.install(with: Options(), breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance(), andNotificationCenterWrapper: TestNSNotificationCenterWrapper())) + sut.install(with: Options(), breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance(), andNotificationCenterWrapper: SentryNSNotificationCenterWrapper())) XCTAssertEqual(1, fixture.tracker.startInvocations.count) XCTAssertEqual(1, fixture.tracker.startSwizzleInvocations.count) @@ -37,7 +37,7 @@ class SentryAutoBreadcrumbTrackingIntegrationTests: XCTestCase { let options = Options() options.enableSwizzling = false - sut.install(with: options, breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance(), andNotificationCenterWrapper: TestNSNotificationCenterWrapper())) + sut.install(with: options, breadcrumbTracker: fixture.tracker, systemEventBreadcrumbs: SentrySystemEventBreadcrumbs(fileManager: SentryDependencyContainer.sharedInstance().fileManager, andCurrentDateProvider: DefaultCurrentDateProvider.sharedInstance(), andNotificationCenterWrapper: SentryNSNotificationCenterWrapper())) XCTAssertEqual(1, fixture.tracker.startInvocations.count) XCTAssertEqual(0, fixture.tracker.startSwizzleInvocations.count) From fac5542da7de7690d5a7dbe989aee4acd2815c09 Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Tue, 6 Dec 2022 09:59:26 +0100 Subject: [PATCH 6/9] Use the wrapper also for observing --- .../ImageProcessing/ColorArt.swift | 2 +- .../PerformanceViewController.swift | 2 +- .../SentryNSNotificationCenterWrapper.m | 11 ++++ Sources/Sentry/SentrySystemEventBreadcrumbs.m | 56 +++++++++---------- .../SentryNSNotificationCenterWrapper.h | 5 ++ .../SentryAppStartTrackerTests.swift | 4 +- .../Networking/SentryHttpTransportTests.swift | 2 +- .../SentryCrashReportSinkTests.swift | 2 +- 8 files changed, 47 insertions(+), 37 deletions(-) diff --git a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift index e59a410d2e..b0c6a7b2d8 100644 --- a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift +++ b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift @@ -319,7 +319,7 @@ private struct RGBADecimalComponents: Hashable { // Relative luminance formula: https://en.wikipedia.org/wiki/Relative_luminance var luminance: CGFloat { - 0.212_6 * r + 0.715_2 * g + 0.072_2 * b + 0.2126 * r + 0.7152 * g + 0.0722 * b } var isDarkColor: Bool { diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift index b4f81dd1a4..aaca80224b 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift @@ -37,7 +37,7 @@ class PerformanceViewController: UIViewController { // refresh rate of 60 hz is 0.0167 // 120 hz is 0.0083 // 240 hz is 0.004167 - private let interval = 0.000_000_05 + private let interval = 0.00000005 private var timer: Timer? private let iterations = 5_000_000 diff --git a/Sources/Sentry/SentryNSNotificationCenterWrapper.m b/Sources/Sentry/SentryNSNotificationCenterWrapper.m index d658f727c9..763da0186a 100644 --- a/Sources/Sentry/SentryNSNotificationCenterWrapper.m +++ b/Sources/Sentry/SentryNSNotificationCenterWrapper.m @@ -51,6 +51,17 @@ - (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSNotificationNam object:nil]; } +- (void)addObserver:(id)observer + selector:(SEL)aSelector + name:(NSNotificationName)aName + object:(id)anObject +{ + [NSNotificationCenter.defaultCenter addObserver:observer + selector:aSelector + name:aName + object:anObject]; +} + - (void)removeObserver:(id)observer name:(NSNotificationName)aName { [NSNotificationCenter.defaultCenter removeObserver:observer name:aName object:nil]; diff --git a/Sources/Sentry/SentrySystemEventBreadcrumbs.m b/Sources/Sentry/SentrySystemEventBreadcrumbs.m index b65af0925b..1dc1917f5f 100644 --- a/Sources/Sentry/SentrySystemEventBreadcrumbs.m +++ b/Sources/Sentry/SentrySystemEventBreadcrumbs.m @@ -95,18 +95,17 @@ - (void)initBatteryObserver:(UIDevice *)currentDevice currentDevice.batteryMonitoringEnabled = YES; } - NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - // Posted when the battery level changes. - [defaultCenter addObserver:self - selector:@selector(batteryStateChanged:) - name:UIDeviceBatteryLevelDidChangeNotification - object:currentDevice]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(batteryStateChanged:) + name:UIDeviceBatteryLevelDidChangeNotification + object:currentDevice]; + // Posted when battery state changes. - [defaultCenter addObserver:self - selector:@selector(batteryStateChanged:) - name:UIDeviceBatteryStateDidChangeNotification - object:currentDevice]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(batteryStateChanged:) + name:UIDeviceBatteryStateDidChangeNotification + object:currentDevice]; } - (void)batteryStateChanged:(NSNotification *)notification @@ -155,10 +154,10 @@ - (void)initOrientationObserver:(UIDevice *)currentDevice } // Posted when the orientation of the device changes. - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(orientationChanged:) - name:UIDeviceOrientationDidChangeNotification - object:currentDevice]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(orientationChanged:) + name:UIDeviceOrientationDidChangeNotification + object:currentDevice]; } - (void)orientationChanged:(NSNotification *)notification @@ -186,18 +185,15 @@ - (void)orientationChanged:(NSNotification *)notification - (void)initKeyboardVisibilityObserver { - NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; // Posted immediately after the display of the keyboard. - [defaultCenter addObserver:self - selector:@selector(systemEventTriggered:) - name:UIKeyboardDidShowNotification - object:nil]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(systemEventTriggered:) + name:UIKeyboardDidShowNotification]; // Posted immediately after the dismissal of the keyboard. - [defaultCenter addObserver:self - selector:@selector(systemEventTriggered:) - name:UIKeyboardDidHideNotification - object:nil]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(systemEventTriggered:) + name:UIKeyboardDidHideNotification]; } - (void)systemEventTriggered:(NSNotification *)notification @@ -212,10 +208,9 @@ - (void)systemEventTriggered:(NSNotification *)notification - (void)initScreenshotObserver { // it's only about the action, but not the SS itself - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(systemEventTriggered:) - name:UIApplicationUserDidTakeScreenshotNotification - object:nil]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(systemEventTriggered:) + name:UIApplicationUserDidTakeScreenshotNotification]; } - (void)initTimezoneObserver @@ -231,10 +226,9 @@ - (void)initTimezoneObserver } // Posted when the timezone of the device changed - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(timezoneEventTriggered) - name:NSSystemTimeZoneDidChangeNotification - object:nil]; + [self.notificationCenterWrapper addObserver:self + selector:@selector(timezoneEventTriggered) + name:NSSystemTimeZoneDidChangeNotification]; } - (void)timezoneEventTriggered diff --git a/Sources/Sentry/include/SentryNSNotificationCenterWrapper.h b/Sources/Sentry/include/SentryNSNotificationCenterWrapper.h index 2c6dd57ae8..39ddcc0998 100644 --- a/Sources/Sentry/include/SentryNSNotificationCenterWrapper.h +++ b/Sources/Sentry/include/SentryNSNotificationCenterWrapper.h @@ -20,6 +20,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSNotificationName)aName; +- (void)addObserver:(id)observer + selector:(SEL)aSelector + name:(NSNotificationName)aName + object:(id)anObject; + - (void)removeObserver:(id)observer name:(NSNotificationName)aName; - (void)removeObserver:(id)observer; diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift index 21557232de..d64d034fbc 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift @@ -397,7 +397,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { let expectedAppStartDuration = expectedDuration ?? fixture.appStartDuration let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.000_1) + XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.0001) if preWarmed { XCTAssertEqual(fixture.moduleInitializationTimestamp, appStartMeasurement.appStartTimestamp) @@ -420,7 +420,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { XCTAssertEqual(type.rawValue, appStartMeasurement.type.rawValue) let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.000_1) + XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.0001) XCTAssertEqual(fixture.sysctl.processStartTimestamp, appStartMeasurement.appStartTimestamp) XCTAssertEqual(fixture.runtimeInitTimestamp, appStartMeasurement.runtimeInitTimestamp) diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 40a8a6090e..4d1042197c 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -528,7 +528,7 @@ class SentryHttpTransportTests: XCTestCase { func testSendEnvelopesConcurrent() { self.measure { - fixture.requestManager.responseDelay = 0.000_1 + fixture.requestManager.responseDelay = 0.0001 let queue = fixture.queue diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 211c841f90..0bfbe70368 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -89,7 +89,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { } func testAppStartCrash_DurationTooBig_DoesNotCallFlush() { - fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.000_01 + fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.00001 filterReportWithAttachment() From 78b1ffb5729ad70500f378fd7773a107b75553f3 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 6 Dec 2022 09:01:26 +0000 Subject: [PATCH 7/9] Format code --- .../TrendingMovies/ImageProcessing/ColorArt.swift | 2 +- .../iOS-Swift/ViewControllers/PerformanceViewController.swift | 2 +- .../AppStartTracking/SentryAppStartTrackerTests.swift | 4 ++-- Tests/SentryTests/Networking/SentryHttpTransportTests.swift | 2 +- .../SentryTests/SentryCrash/SentryCrashReportSinkTests.swift | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift index b0c6a7b2d8..e59a410d2e 100644 --- a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift +++ b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift @@ -319,7 +319,7 @@ private struct RGBADecimalComponents: Hashable { // Relative luminance formula: https://en.wikipedia.org/wiki/Relative_luminance var luminance: CGFloat { - 0.2126 * r + 0.7152 * g + 0.0722 * b + 0.212_6 * r + 0.715_2 * g + 0.072_2 * b } var isDarkColor: Bool { diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift index aaca80224b..b4f81dd1a4 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift @@ -37,7 +37,7 @@ class PerformanceViewController: UIViewController { // refresh rate of 60 hz is 0.0167 // 120 hz is 0.0083 // 240 hz is 0.004167 - private let interval = 0.00000005 + private let interval = 0.000_000_05 private var timer: Timer? private let iterations = 5_000_000 diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift index d64d034fbc..21557232de 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift @@ -397,7 +397,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { let expectedAppStartDuration = expectedDuration ?? fixture.appStartDuration let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.0001) + XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.000_1) if preWarmed { XCTAssertEqual(fixture.moduleInitializationTimestamp, appStartMeasurement.appStartTimestamp) @@ -420,7 +420,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { XCTAssertEqual(type.rawValue, appStartMeasurement.type.rawValue) let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.0001) + XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.000_1) XCTAssertEqual(fixture.sysctl.processStartTimestamp, appStartMeasurement.appStartTimestamp) XCTAssertEqual(fixture.runtimeInitTimestamp, appStartMeasurement.runtimeInitTimestamp) diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 4d1042197c..40a8a6090e 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -528,7 +528,7 @@ class SentryHttpTransportTests: XCTestCase { func testSendEnvelopesConcurrent() { self.measure { - fixture.requestManager.responseDelay = 0.0001 + fixture.requestManager.responseDelay = 0.000_1 let queue = fixture.queue diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 0bfbe70368..211c841f90 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -89,7 +89,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { } func testAppStartCrash_DurationTooBig_DoesNotCallFlush() { - fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.00001 + fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.000_01 filterReportWithAttachment() From 7eeb4e419b17814cab229612c4f863b47d932360 Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Tue, 6 Dec 2022 10:38:01 +0100 Subject: [PATCH 8/9] Fix tests --- .../TrendingMovies/ImageProcessing/ColorArt.swift | 2 +- .../iOS-Swift/ViewControllers/PerformanceViewController.swift | 2 +- .../SentryTests/Helper/TestNSNotificationCenterWrapper.swift | 3 +++ .../AppStartTracking/SentryAppStartTrackerTests.swift | 4 ++-- Tests/SentryTests/Networking/SentryHttpTransportTests.swift | 2 +- .../SentryTests/SentryCrash/SentryCrashReportSinkTests.swift | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift index e59a410d2e..b0c6a7b2d8 100644 --- a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift +++ b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift @@ -319,7 +319,7 @@ private struct RGBADecimalComponents: Hashable { // Relative luminance formula: https://en.wikipedia.org/wiki/Relative_luminance var luminance: CGFloat { - 0.212_6 * r + 0.715_2 * g + 0.072_2 * b + 0.2126 * r + 0.7152 * g + 0.0722 * b } var isDarkColor: Bool { diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift index b4f81dd1a4..aaca80224b 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift @@ -37,7 +37,7 @@ class PerformanceViewController: UIViewController { // refresh rate of 60 hz is 0.0167 // 120 hz is 0.0083 // 240 hz is 0.004167 - private let interval = 0.000_000_05 + private let interval = 0.00000005 private var timer: Timer? private let iterations = 5_000_000 diff --git a/Tests/SentryTests/Helper/TestNSNotificationCenterWrapper.swift b/Tests/SentryTests/Helper/TestNSNotificationCenterWrapper.swift index 1d9fc0e2f6..b49c25c555 100644 --- a/Tests/SentryTests/Helper/TestNSNotificationCenterWrapper.swift +++ b/Tests/SentryTests/Helper/TestNSNotificationCenterWrapper.swift @@ -8,15 +8,18 @@ import Foundation public override func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name) { addObserverInvocations.record((observer, aSelector, aName)) + NotificationCenter.default.addObserver(observer, selector: aSelector, name: aName, object: nil) } var removeObserverWithNameInvocations = Invocations<(observer: Any, name: NSNotification.Name)>() public override func removeObserver(_ observer: Any, name aName: NSNotification.Name) { removeObserverWithNameInvocations.record((observer, aName)) + NotificationCenter.default.removeObserver(observer, name: aName, object: nil) } var removeObserverInvocations = Invocations() public override func removeObserver(_ observer: Any) { removeObserverInvocations.record(observer) + NotificationCenter.default.removeObserver(observer) } } diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift index 21557232de..d64d034fbc 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift @@ -397,7 +397,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { let expectedAppStartDuration = expectedDuration ?? fixture.appStartDuration let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.000_1) + XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.0001) if preWarmed { XCTAssertEqual(fixture.moduleInitializationTimestamp, appStartMeasurement.appStartTimestamp) @@ -420,7 +420,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { XCTAssertEqual(type.rawValue, appStartMeasurement.type.rawValue) let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.000_1) + XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.0001) XCTAssertEqual(fixture.sysctl.processStartTimestamp, appStartMeasurement.appStartTimestamp) XCTAssertEqual(fixture.runtimeInitTimestamp, appStartMeasurement.runtimeInitTimestamp) diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 40a8a6090e..4d1042197c 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -528,7 +528,7 @@ class SentryHttpTransportTests: XCTestCase { func testSendEnvelopesConcurrent() { self.measure { - fixture.requestManager.responseDelay = 0.000_1 + fixture.requestManager.responseDelay = 0.0001 let queue = fixture.queue diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 211c841f90..0bfbe70368 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -89,7 +89,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { } func testAppStartCrash_DurationTooBig_DoesNotCallFlush() { - fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.000_01 + fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.00001 filterReportWithAttachment() From 74af8b27a7fead5f1ea65b2134ce95ea092f54ba Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 6 Dec 2022 09:40:10 +0000 Subject: [PATCH 9/9] Format code --- .../TrendingMovies/ImageProcessing/ColorArt.swift | 2 +- .../iOS-Swift/ViewControllers/PerformanceViewController.swift | 2 +- .../AppStartTracking/SentryAppStartTrackerTests.swift | 4 ++-- Tests/SentryTests/Networking/SentryHttpTransportTests.swift | 2 +- .../SentryTests/SentryCrash/SentryCrashReportSinkTests.swift | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift index b0c6a7b2d8..e59a410d2e 100644 --- a/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift +++ b/Samples/TrendingMovies/TrendingMovies/ImageProcessing/ColorArt.swift @@ -319,7 +319,7 @@ private struct RGBADecimalComponents: Hashable { // Relative luminance formula: https://en.wikipedia.org/wiki/Relative_luminance var luminance: CGFloat { - 0.2126 * r + 0.7152 * g + 0.0722 * b + 0.212_6 * r + 0.715_2 * g + 0.072_2 * b } var isDarkColor: Bool { diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift index aaca80224b..b4f81dd1a4 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift @@ -37,7 +37,7 @@ class PerformanceViewController: UIViewController { // refresh rate of 60 hz is 0.0167 // 120 hz is 0.0083 // 240 hz is 0.004167 - private let interval = 0.00000005 + private let interval = 0.000_000_05 private var timer: Timer? private let iterations = 5_000_000 diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift index d64d034fbc..21557232de 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift @@ -397,7 +397,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { let expectedAppStartDuration = expectedDuration ?? fixture.appStartDuration let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.0001) + XCTAssertEqual(expectedAppStartDuration, actualAppStartDuration, accuracy: 0.000_1) if preWarmed { XCTAssertEqual(fixture.moduleInitializationTimestamp, appStartMeasurement.appStartTimestamp) @@ -420,7 +420,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase { XCTAssertEqual(type.rawValue, appStartMeasurement.type.rawValue) let actualAppStartDuration = appStartMeasurement.duration - XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.0001) + XCTAssertEqual(0.0, actualAppStartDuration, accuracy: 0.000_1) XCTAssertEqual(fixture.sysctl.processStartTimestamp, appStartMeasurement.appStartTimestamp) XCTAssertEqual(fixture.runtimeInitTimestamp, appStartMeasurement.runtimeInitTimestamp) diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 4d1042197c..40a8a6090e 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -528,7 +528,7 @@ class SentryHttpTransportTests: XCTestCase { func testSendEnvelopesConcurrent() { self.measure { - fixture.requestManager.responseDelay = 0.0001 + fixture.requestManager.responseDelay = 0.000_1 let queue = fixture.queue diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 0bfbe70368..211c841f90 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -89,7 +89,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { } func testAppStartCrash_DurationTooBig_DoesNotCallFlush() { - fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.00001 + fixture.crashWrapper.internalDurationFromCrashStateInitToLastCrash = 2.000_01 filterReportWithAttachment()