From 4ab9f01e62571036bf5d127030b8bbb018e1cd07 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 23 Jun 2023 16:02:17 -0800 Subject: [PATCH 1/2] ref: rename SentryTimerWrapper to SentryTimerFactory since it's no longer a subclass after the recent fixes, it's now a factory --- Sentry.xcodeproj/project.pbxproj | 34 +++++++++---------- .../SentryTestUtils-ObjC-BridgingHeader.h | 2 +- ...r.swift => TestSentryNSTimerFactory.swift} | 2 +- Sources/Sentry/SentryHub.m | 2 +- Sources/Sentry/SentryMetricProfiler.mm | 2 +- ...STimerWrapper.m => SentryNSTimerFactory.m} | 4 +-- Sources/Sentry/SentryProfiler.mm | 14 ++++---- Sources/Sentry/SentryTracer.m | 8 ++--- Sources/Sentry/include/SentryHub+Private.h | 2 +- ...STimerWrapper.h => SentryNSTimerFactory.h} | 2 +- Sources/Sentry/include/SentryTracer.h | 2 +- .../include/SentryTracerConfiguration.h | 4 +-- ...t.swift => SentryNSTimerFactoryTest.swift} | 4 +-- .../SentryProfilerSwiftTests.swift | 16 ++++----- .../Helper/SentryProfiler+SwiftTest.h | 2 +- Tests/SentryTests/SentryNSTimerWrapper+Test.h | 6 ---- .../SentryTests/SentryTests-Bridging-Header.h | 4 +-- .../Transaction/SentryTracerTests.swift | 12 +++---- 18 files changed, 57 insertions(+), 65 deletions(-) rename SentryTestUtils/{TestSentryNSTimerWrapper.swift => TestSentryNSTimerFactory.swift} (96%) rename Sources/Sentry/{SentryNSTimerWrapper.m => SentryNSTimerFactory.m} (92%) rename Sources/Sentry/include/{SentryNSTimerWrapper.h => SentryNSTimerFactory.h} (93%) rename Tests/SentryProfilerTests/{SentryNSTimerWrapperTest.swift => SentryNSTimerFactoryTest.swift} (89%) delete mode 100644 Tests/SentryTests/SentryNSTimerWrapper+Test.h diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 7ffc76dbe44..6a7cc1753b1 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -610,11 +610,11 @@ 8431EFDF29B27B5300D8DC56 /* SentryThreadHandleTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73C927D57398005EEB11 /* SentryThreadHandleTests.mm */; }; 8431EFE029B27B5300D8DC56 /* SentryBacktraceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73C727D56757005EEB11 /* SentryBacktraceTests.mm */; }; 8431EFE129B27B5300D8DC56 /* SentryThreadMetadataCacheTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 035E73CD27D5790A005EEB11 /* SentryThreadMetadataCacheTests.mm */; }; - 8431EFE229B27BAD00D8DC56 /* SentryNSTimerWrapperTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849472842971C41A002603DE /* SentryNSTimerWrapperTest.swift */; }; + 8431EFE229B27BAD00D8DC56 /* SentryNSTimerFactoryTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849472842971C41A002603DE /* SentryNSTimerFactoryTest.swift */; }; 8431EFE529B27BAD00D8DC56 /* SentryNSProcessInfoWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849472822971C2CD002603DE /* SentryNSProcessInfoWrapperTests.swift */; }; 8431EFE829B27BAD00D8DC56 /* SentrySystemWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849472802971C107002603DE /* SentrySystemWrapperTests.swift */; }; 8431F00529B2849A00D8DC56 /* (null) in Sources */ = {isa = PBXBuildFile; }; - 8431F01529B2851500D8DC56 /* TestSentryNSTimerWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844EDCE72947DCD700C86F34 /* TestSentryNSTimerWrapper.swift */; }; + 8431F01529B2851500D8DC56 /* TestSentryNSTimerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844EDCE72947DCD700C86F34 /* TestSentryNSTimerFactory.swift */; }; 8431F01629B2851500D8DC56 /* TestSentryNSProcessInfoWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844EDC712941442200C86F34 /* TestSentryNSProcessInfoWrapper.swift */; }; 8431F01729B2851500D8DC56 /* TestSentrySystemWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844EDC7829415AB300C86F34 /* TestSentrySystemWrapper.swift */; }; 8431F01829B2852D00D8DC56 /* TypeMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E4A038325F76A7600000D77 /* TypeMapping.swift */; }; @@ -628,8 +628,8 @@ 844EDC70294143B900C86F34 /* SentryNSProcessInfoWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 844EDC6E294143B900C86F34 /* SentryNSProcessInfoWrapper.mm */; }; 844EDC76294144DB00C86F34 /* SentrySystemWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 844EDC74294144DB00C86F34 /* SentrySystemWrapper.h */; }; 844EDC77294144DB00C86F34 /* SentrySystemWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 844EDC75294144DB00C86F34 /* SentrySystemWrapper.mm */; }; - 844EDCE52947DC3100C86F34 /* SentryNSTimerWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 844EDCE32947DC3100C86F34 /* SentryNSTimerWrapper.h */; }; - 844EDCE62947DC3100C86F34 /* SentryNSTimerWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 844EDCE42947DC3100C86F34 /* SentryNSTimerWrapper.m */; }; + 844EDCE52947DC3100C86F34 /* SentryNSTimerFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 844EDCE32947DC3100C86F34 /* SentryNSTimerFactory.h */; }; + 844EDCE62947DC3100C86F34 /* SentryNSTimerFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 844EDCE42947DC3100C86F34 /* SentryNSTimerFactory.m */; }; 844EDD6C2949387000C86F34 /* SentryMetricProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 844EDD6B2949387000C86F34 /* SentryMetricProfiler.h */; }; 8453421228BE855D00C22EEC /* SentrySampleDecision.m in Sources */ = {isa = PBXBuildFile; fileRef = 8453421128BE855D00C22EEC /* SentrySampleDecision.m */; }; 8453421628BE8A9500C22EEC /* SentrySpanStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */; }; @@ -1557,17 +1557,16 @@ 844EDC75294144DB00C86F34 /* SentrySystemWrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentrySystemWrapper.mm; sourceTree = ""; }; 844EDC7829415AB300C86F34 /* TestSentrySystemWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentrySystemWrapper.swift; sourceTree = ""; }; 844EDC7B2942843400C86F34 /* SentryProfiler+SwiftTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryProfiler+SwiftTest.h"; path = "Tests/SentryTests/Helper/SentryProfiler+SwiftTest.h"; sourceTree = SOURCE_ROOT; }; - 844EDCE32947DC3100C86F34 /* SentryNSTimerWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryNSTimerWrapper.h; path = include/SentryNSTimerWrapper.h; sourceTree = ""; }; - 844EDCE42947DC3100C86F34 /* SentryNSTimerWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSTimerWrapper.m; sourceTree = ""; }; - 844EDCE72947DCD700C86F34 /* TestSentryNSTimerWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryNSTimerWrapper.swift; sourceTree = ""; }; - 844EDCE92947E78B00C86F34 /* SentryNSTimerWrapper+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryNSTimerWrapper+Test.h"; sourceTree = ""; }; + 844EDCE32947DC3100C86F34 /* SentryNSTimerFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryNSTimerFactory.h; path = include/SentryNSTimerFactory.h; sourceTree = ""; }; + 844EDCE42947DC3100C86F34 /* SentryNSTimerFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSTimerFactory.m; sourceTree = ""; }; + 844EDCE72947DCD700C86F34 /* TestSentryNSTimerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryNSTimerFactory.swift; sourceTree = ""; }; 844EDD6B2949387000C86F34 /* SentryMetricProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryMetricProfiler.h; path = Sources/Sentry/include/SentryMetricProfiler.h; sourceTree = SOURCE_ROOT; }; 8453421128BE855D00C22EEC /* SentrySampleDecision.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySampleDecision.m; sourceTree = ""; }; 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySpanStatus.m; sourceTree = ""; }; 8454CF8B293EAF9A006AC140 /* SentryMetricProfiler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryMetricProfiler.mm; path = Sources/Sentry/SentryMetricProfiler.mm; sourceTree = SOURCE_ROOT; }; 849472802971C107002603DE /* SentrySystemWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySystemWrapperTests.swift; sourceTree = ""; }; 849472822971C2CD002603DE /* SentryNSProcessInfoWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSProcessInfoWrapperTests.swift; sourceTree = ""; }; - 849472842971C41A002603DE /* SentryNSTimerWrapperTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerWrapperTest.swift; sourceTree = ""; }; + 849472842971C41A002603DE /* SentryNSTimerFactoryTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerFactoryTest.swift; sourceTree = ""; }; 849AC3FF29E0C1FF00889C16 /* SentryFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryFormatterTests.swift; sourceTree = ""; }; 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Sentry.swift"; sourceTree = ""; }; 84A888FC28D9B11700C51DFD /* SentryProfiler+Test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SentryProfiler+Test.h"; path = "Sources/Sentry/include/SentryProfiler+Test.h"; sourceTree = SOURCE_ROOT; }; @@ -2171,8 +2170,8 @@ 844EDC6E294143B900C86F34 /* SentryNSProcessInfoWrapper.mm */, 844EDC74294144DB00C86F34 /* SentrySystemWrapper.h */, 844EDC75294144DB00C86F34 /* SentrySystemWrapper.mm */, - 844EDCE32947DC3100C86F34 /* SentryNSTimerWrapper.h */, - 844EDCE42947DC3100C86F34 /* SentryNSTimerWrapper.m */, + 844EDCE32947DC3100C86F34 /* SentryNSTimerFactory.h */, + 844EDCE42947DC3100C86F34 /* SentryNSTimerFactory.m */, 33042A0B29DAF5F400C60085 /* SentryExtraContextProvider.h */, 33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */, D858FA642A29EAB3002A3503 /* SentryBinaryImageCache.h */, @@ -2211,7 +2210,6 @@ isa = PBXGroup; children = ( 7B3878E92490D90400EBDEA2 /* SentryClient+TestInit.h */, - 844EDCE92947E78B00C86F34 /* SentryNSTimerWrapper+Test.h */, 7B569DFE2590EEF600B653FC /* SentryScope+Equality.h */, 7B569E052590F04700B653FC /* SentryScope+Properties.h */, 7B9421C4260CA393001F9349 /* SentrySDK+Tests.h */, @@ -3129,7 +3127,7 @@ children = ( 849472802971C107002603DE /* SentrySystemWrapperTests.swift */, 849472822971C2CD002603DE /* SentryNSProcessInfoWrapperTests.swift */, - 849472842971C41A002603DE /* SentryNSTimerWrapperTest.swift */, + 849472842971C41A002603DE /* SentryNSTimerFactoryTest.swift */, 035E73C727D56757005EEB11 /* SentryBacktraceTests.mm */, 035E73C927D57398005EEB11 /* SentryThreadHandleTests.mm */, 035E73CB27D575B3005EEB11 /* SentrySamplingProfilerTests.mm */, @@ -3170,7 +3168,7 @@ 8431EFEE29B2831000D8DC56 /* Dynamic */, 844EDC712941442200C86F34 /* TestSentryNSProcessInfoWrapper.swift */, 844EDC7829415AB300C86F34 /* TestSentrySystemWrapper.swift */, - 844EDCE72947DCD700C86F34 /* TestSentryNSTimerWrapper.swift */, + 844EDCE72947DCD700C86F34 /* TestSentryNSTimerFactory.swift */, 84B7FA3B29B2866200AD93B1 /* SentryTestUtils-ObjC-BridgingHeader.h */, ); path = SentryTestUtils; @@ -3600,7 +3598,7 @@ 7BD86EC5264A63F6005439DB /* SentrySysctl.h in Headers */, 63BE85701ECEC6DE00DC44F5 /* NSDate+SentryExtras.h in Headers */, 63FE709520DA4C1000CDBAE8 /* SentryCrashReportFilterBasic.h in Headers */, - 844EDCE52947DC3100C86F34 /* SentryNSTimerWrapper.h in Headers */, + 844EDCE52947DC3100C86F34 /* SentryNSTimerFactory.h in Headers */, D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */, 63FE70A120DA4C1000CDBAE8 /* SentryCrashCString.h in Headers */, 7B63459D280EBA6300CFA05A /* SentryUIEventTracker.h in Headers */, @@ -4063,7 +4061,7 @@ A8F17B2E2901765900990B25 /* SentryRequest.m in Sources */, 7BE1E33424F7E3CB009D3AD0 /* SentryMigrateSessionInit.m in Sources */, 15E0A8F22411A45A00F044E3 /* SentrySession.m in Sources */, - 844EDCE62947DC3100C86F34 /* SentryNSTimerWrapper.m in Sources */, + 844EDCE62947DC3100C86F34 /* SentryNSTimerFactory.m in Sources */, 7B6D1261265F784000C9BE4B /* PrivateSentrySDKOnly.m in Sources */, 63BE85711ECEC6DE00DC44F5 /* NSDate+SentryExtras.m in Sources */, 7BD4BD4927EB2A5D0071F4FF /* SentryDiscardedEvent.m in Sources */, @@ -4411,7 +4409,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8431EFE229B27BAD00D8DC56 /* SentryNSTimerWrapperTest.swift in Sources */, + 8431EFE229B27BAD00D8DC56 /* SentryNSTimerFactoryTest.swift in Sources */, 8431EFDD29B27B5300D8DC56 /* SentrySamplingProfilerTests.mm in Sources */, 8431EFDC29B27B5300D8DC56 /* SentryProfilerTests.mm in Sources */, 8431EFE129B27B5300D8DC56 /* SentryThreadMetadataCacheTests.mm in Sources */, @@ -4434,7 +4432,7 @@ 84AC61D929F7643B009EEF61 /* TestDispatchFactory.swift in Sources */, 8431F01929B2852D00D8DC56 /* Invocation.swift in Sources */, 84B7FA4629B2935F00AD93B1 /* ClearTestState.swift in Sources */, - 8431F01529B2851500D8DC56 /* TestSentryNSTimerWrapper.swift in Sources */, + 8431F01529B2851500D8DC56 /* TestSentryNSTimerFactory.swift in Sources */, 84B7FA3C29B2876F00AD93B1 /* TestConstants.swift in Sources */, 8431F01A29B2852D00D8DC56 /* Dynamic.swift in Sources */, 84B7FA4329B28D8C00AD93B1 /* Invocations.swift in Sources */, diff --git a/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h b/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h index c967b0b536a..112370d7aa2 100644 --- a/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h +++ b/SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h @@ -18,7 +18,7 @@ #import "SentryGlobalEventProcessor.h" #import "SentryLog.h" #import "SentryNSProcessInfoWrapper.h" -#import "SentryNSTimerWrapper.h" +#import "SentryNSTimerFactory.h" #import "SentryNetworkTracker.h" #import "SentryPerformanceTracker+Testing.h" #import "SentryRandom.h" diff --git a/SentryTestUtils/TestSentryNSTimerWrapper.swift b/SentryTestUtils/TestSentryNSTimerFactory.swift similarity index 96% rename from SentryTestUtils/TestSentryNSTimerWrapper.swift rename to SentryTestUtils/TestSentryNSTimerFactory.swift index 96ad8ef6d31..7e9fe92f2c2 100644 --- a/SentryTestUtils/TestSentryNSTimerWrapper.swift +++ b/SentryTestUtils/TestSentryNSTimerFactory.swift @@ -3,7 +3,7 @@ import Sentry // We must not subclass NSTimer, see https://developer.apple.com/documentation/foundation/nstimer#1770465. // Therefore we return a NSTimer instance here with TimeInterval.infinity. -public class TestSentryNSTimerWrapper: SentryNSTimerWrapper { +public class TestSentryNSTimerFactory: SentryNSTimerFactory { public struct Overrides { private var _timer: Timer? diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index bd4941bc0c4..64ef3af3a2c 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -11,7 +11,7 @@ #import "SentryId.h" #import "SentryLevelMapper.h" #import "SentryLog.h" -#import "SentryNSTimerWrapper.h" +#import "SentryNSTimerFactory.h" #import "SentryPerformanceTracker.h" #import "SentryProfilesSampler.h" #import "SentrySDK+Private.h" diff --git a/Sources/Sentry/SentryMetricProfiler.mm b/Sources/Sentry/SentryMetricProfiler.mm index edb6b04b03c..b675b13a960 100644 --- a/Sources/Sentry/SentryMetricProfiler.mm +++ b/Sources/Sentry/SentryMetricProfiler.mm @@ -10,7 +10,7 @@ # import "SentryFormatter.h" # import "SentryLog.h" # import "SentryNSProcessInfoWrapper.h" -# import "SentryNSTimerWrapper.h" +# import "SentryNSTimerFactory.h" # import "SentrySystemWrapper.h" # import "SentryTime.h" # import "SentryTransaction.h" diff --git a/Sources/Sentry/SentryNSTimerWrapper.m b/Sources/Sentry/SentryNSTimerFactory.m similarity index 92% rename from Sources/Sentry/SentryNSTimerWrapper.m rename to Sources/Sentry/SentryNSTimerFactory.m index 6a9ffef47c5..4087fb22097 100644 --- a/Sources/Sentry/SentryNSTimerWrapper.m +++ b/Sources/Sentry/SentryNSTimerFactory.m @@ -1,6 +1,6 @@ -#import "SentryNSTimerWrapper.h" +#import "SentryNSTimerFactory.h" -@implementation SentryNSTimerWrapper +@implementation SentryNSTimerFactory - (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 904c2999e09..f66dcb85e7e 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -24,7 +24,7 @@ # import "SentryLog.h" # import "SentryMetricProfiler.h" # import "SentryNSProcessInfoWrapper.h" -# import "SentryNSTimerWrapper.h" +# import "SentryNSTimerFactory.h" # import "SentryProfileTimeseries.h" # import "SentrySamplingProfiler.hpp" # import "SentryScope+Private.h" @@ -84,7 +84,7 @@ SentryNSProcessInfoWrapper *_gCurrentProcessInfoWrapper; SentrySystemWrapper *_gCurrentSystemWrapper; SentryDispatchFactory *_gDispatchFactory; -SentryNSTimerWrapper *_gTimeoutTimerWrapper; +SentryNSTimerFactory *_gTimeoutTimerFactory; NSString * profilerTruncationReasonName(SentryProfilerTruncationReason reason) @@ -485,11 +485,11 @@ + (void)startWithHub:(SentryHub *)hub [_gCurrentProfiler start]; - if (_gTimeoutTimerWrapper == nil) { - _gTimeoutTimerWrapper = [[SentryNSTimerWrapper alloc] init]; + if (_gTimeoutTimerFactory == nil) { + _gTimeoutTimerFactory = [[SentryNSTimerFactory alloc] init]; } _gCurrentProfiler->_timeoutTimer = - [_gTimeoutTimerWrapper scheduledTimerWithTimeInterval:kSentryProfilerTimeoutInterval + [_gTimeoutTimerFactory scheduledTimerWithTimeInterval:kSentryProfilerTimeoutInterval target:self selector:@selector(timeoutAbort) userInfo:nil @@ -558,10 +558,10 @@ + (void)useDispatchFactory:(SentryDispatchFactory *)dispatchFactory _gDispatchFactory = dispatchFactory; } -+ (void)useTimeoutTimerWrapper:(SentryNSTimerWrapper *)timerWrapper ++ (void)useTimeoutTimerWrapper:(SentryNSTimerFactory *)timerWrapper { std::lock_guard l(_gProfilerLock); - _gTimeoutTimerWrapper = timerWrapper; + _gTimeoutTimerFactory = timerWrapper; } # pragma mark - Private diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 363c751b73a..a866617ced0 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -10,7 +10,7 @@ #import "SentryFramesTracker.h" #import "SentryHub+Private.h" #import "SentryLog.h" -#import "SentryNSTimerWrapper.h" +#import "SentryNSTimerFactory.h" #import "SentryNoOpSpan.h" #import "SentryProfiler.h" #import "SentryProfilesSampler.h" @@ -120,8 +120,8 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti _measurements = [[NSMutableDictionary alloc] init]; self.finishStatus = kSentrySpanStatusUndefined; - if (_configuration.timerWrapper == nil) { - _configuration.timerWrapper = [[SentryNSTimerWrapper alloc] init]; + if (_configuration.timerFactory == nil) { + _configuration.timerFactory = [[SentryNSTimerFactory alloc] init]; } appStartMeasurement = [self getAppStartMeasurement]; @@ -214,7 +214,7 @@ - (void)startDeadlineTimer { __weak SentryTracer *weakSelf = self; self.deadlineTimer = - [_configuration.timerWrapper scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE + [_configuration.timerFactory scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE repeats:NO block:^(NSTimer *_Nonnull timer) { if (weakSelf == nil) { diff --git a/Sources/Sentry/include/SentryHub+Private.h b/Sources/Sentry/include/SentryHub+Private.h index 025b3a12a1c..552d061ef1f 100644 --- a/Sources/Sentry/include/SentryHub+Private.h +++ b/Sources/Sentry/include/SentryHub+Private.h @@ -2,7 +2,7 @@ #import "SentryTracer.h" @class SentryEnvelopeItem, SentryId, SentryScope, SentryTransaction, SentryDispatchQueueWrapper, - SentryEnvelope, SentryNSTimerWrapper, SentrySession; + SentryEnvelope, SentryNSTimerFactory, SentrySession; NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/include/SentryNSTimerWrapper.h b/Sources/Sentry/include/SentryNSTimerFactory.h similarity index 93% rename from Sources/Sentry/include/SentryNSTimerWrapper.h rename to Sources/Sentry/include/SentryNSTimerFactory.h index 2e80fa83f84..b8200d4fa01 100644 --- a/Sources/Sentry/include/SentryNSTimerWrapper.h +++ b/Sources/Sentry/include/SentryNSTimerFactory.h @@ -2,7 +2,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface SentryNSTimerWrapper : NSObject +@interface SentryNSTimerFactory : NSObject - (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 1a6fab6a8f8..8dcc38bd4ee 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN @class SentryHub, SentryTransactionContext, SentryTraceHeader, SentryTraceContext, - SentryNSTimerWrapper, SentryDispatchQueueWrapper, SentryTracer, SentryProfilesSamplerDecision, + SentryNSTimerFactory, SentryDispatchQueueWrapper, SentryTracer, SentryProfilesSamplerDecision, SentryMeasurementValue; static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; diff --git a/Sources/Sentry/include/SentryTracerConfiguration.h b/Sources/Sentry/include/SentryTracerConfiguration.h index 25070ff20d3..03084b4a8f7 100644 --- a/Sources/Sentry/include/SentryTracerConfiguration.h +++ b/Sources/Sentry/include/SentryTracerConfiguration.h @@ -2,7 +2,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SentryNSTimerWrapper, SentryDispatchQueueWrapper, SentryProfilesSamplerDecision; +@class SentryNSTimerFactory, SentryDispatchQueueWrapper, SentryProfilesSamplerDecision; @interface SentryTracerConfiguration : NSObject @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN /** * A writer around NSTimer, to make it testable */ -@property (nonatomic, strong, nullable) SentryNSTimerWrapper *timerWrapper; +@property (nonatomic, strong, nullable) SentryNSTimerFactory *timerFactory; + (SentryTracerConfiguration *)configurationWithBlock: (void (^)(SentryTracerConfiguration *configuration))block; diff --git a/Tests/SentryProfilerTests/SentryNSTimerWrapperTest.swift b/Tests/SentryProfilerTests/SentryNSTimerFactoryTest.swift similarity index 89% rename from Tests/SentryProfilerTests/SentryNSTimerWrapperTest.swift rename to Tests/SentryProfilerTests/SentryNSTimerFactoryTest.swift index 3ba112b7277..fdef6171b57 100644 --- a/Tests/SentryProfilerTests/SentryNSTimerWrapperTest.swift +++ b/Tests/SentryProfilerTests/SentryNSTimerFactoryTest.swift @@ -1,8 +1,8 @@ import XCTest -class SentryNSTimerWrapperTests: XCTestCase { +class SentryNSTimerFactoryTests: XCTestCase { struct Fixture { - lazy var timerWrapper = SentryNSTimerWrapper() + lazy var timerWrapper = SentryNSTimerFactory() } lazy var fixture = Fixture() diff --git a/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift b/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift index ffb0403b0f6..6c0ad88bc92 100644 --- a/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift +++ b/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift @@ -29,7 +29,7 @@ class SentryProfilerSwiftTests: XCTestCase { lazy var processInfoWrapper = TestSentryNSProcessInfoWrapper() lazy var dispatchFactory = TestDispatchFactory() var metricTimerWrapper: TestDispatchSourceWrapper? - lazy var timeoutTimerWrapper = TestSentryNSTimerWrapper() + lazy var timeoutTimerFactory = TestSentryNSTimerFactory() let currentDateProvider = TestCurrentDateProvider() @@ -43,13 +43,13 @@ class SentryProfilerSwiftTests: XCTestCase { options.profilesSampleRate = 1.0 options.tracesSampleRate = 1.0 - SentryProfiler.useSystemWrapper(systemWrapper) - SentryProfiler.useProcessInfoWrapper(processInfoWrapper) + SentryDependencyContainer.sharedInstance().systemWrapper = systemWrapper + SentryDependencyContainer.sharedInstance().processInfoWrapper = processInfoWrapper dispatchFactory.vendedSourceHandler = { eventHandler in self.metricTimerWrapper = eventHandler } - SentryProfiler.useDispatchFactory(dispatchFactory) - SentryProfiler.useTimeoutTimerWrapper(timeoutTimerWrapper) + SentryDependencyContainer.sharedInstance().dispatchFactory = dispatchFactory + SentryDependencyContainer.sharedInstance().timerFactory = timeoutTimerFactory systemWrapper.overrides.cpuUsagePerCore = mockCPUUsages.map { NSNumber(value: $0) } processInfoWrapper.overrides.processorCount = UInt(mockCPUUsages.count) @@ -221,7 +221,7 @@ class SentryProfilerSwiftTests: XCTestCase { super.tearDown() // If a test early exits because of a thrown error, it may not finish the spans it created. This ensures the profiler stops before starting the next test case. - fixture.timeoutTimerWrapper.fire() + fixture.timeoutTimerFactory.fire() clearTestState() } @@ -282,7 +282,7 @@ class SentryProfilerSwiftTests: XCTestCase { fixture.currentDateProvider.advanceBy(nanoseconds: 1.toNanoSeconds()) forceProfilerSample() fixture.currentDateProvider.advanceBy(nanoseconds: 30.toNanoSeconds()) - fixture.timeoutTimerWrapper.fire() + fixture.timeoutTimerFactory.fire() fixture.currentDateProvider.advanceBy(nanoseconds: 0.5.toNanoSeconds()) @@ -418,7 +418,7 @@ private extension SentryProfilerSwiftTests { forceProfilerSample() fixture.currentDateProvider.advance(by: 31) if shouldTimeOut { - fixture.timeoutTimerWrapper.fire() + fixture.timeoutTimerFactory.fire() } span.finish() diff --git a/Tests/SentryTests/Helper/SentryProfiler+SwiftTest.h b/Tests/SentryTests/Helper/SentryProfiler+SwiftTest.h index a361db2e44b..b5d434f234e 100644 --- a/Tests/SentryTests/Helper/SentryProfiler+SwiftTest.h +++ b/Tests/SentryTests/Helper/SentryProfiler+SwiftTest.h @@ -24,7 +24,7 @@ SentryProfiler () + (void)useDispatchFactory:(SentryDispatchFactory *)dispatchFactory NS_SWIFT_NAME(useDispatchFactory(_:)); -+ (void)useTimeoutTimerWrapper:(SentryNSTimerWrapper *)timerWrapper ++ (void)useTimeoutTimerWrapper:(SentryNSTimerFactory *)timerWrapper NS_SWIFT_NAME(useTimeoutTimerWrapper(_:)); @end diff --git a/Tests/SentryTests/SentryNSTimerWrapper+Test.h b/Tests/SentryTests/SentryNSTimerWrapper+Test.h deleted file mode 100644 index ba40732d01d..00000000000 --- a/Tests/SentryTests/SentryNSTimerWrapper+Test.h +++ /dev/null @@ -1,6 +0,0 @@ -#import "SentryNSTimerWrapper.h" - -@interface -SentryNSTimerWrapper () - -@end diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index da28580386a..fa681edffe0 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -111,7 +111,7 @@ #import "SentryNSError.h" #import "SentryNSNotificationCenterWrapper.h" #import "SentryNSProcessInfoWrapper.h" -#import "SentryNSTimerWrapper.h" +#import "SentryNSTimerFactory.h" #import "SentryNSURLRequest.h" #import "SentryNSURLRequestBuilder.h" #import "SentryNSURLSessionTaskSearch.h" @@ -124,7 +124,7 @@ #import "SentryPerformanceTracker.h" #import "SentryPerformanceTrackingIntegration.h" #import "SentryPredicateDescriptor.h" -#import "SentryProfiler+SwiftTest.h" +#import "SentryProfiler.h" #import "SentryQueueableRequestManager.h" #import "SentryRandom.h" #import "SentryRateLimitParser.h" diff --git a/Tests/SentryTests/Transaction/SentryTracerTests.swift b/Tests/SentryTests/Transaction/SentryTracerTests.swift index 7073d10de18..d14443df49c 100644 --- a/Tests/SentryTests/Transaction/SentryTracerTests.swift +++ b/Tests/SentryTests/Transaction/SentryTracerTests.swift @@ -25,7 +25,7 @@ class SentryTracerTests: XCTestCase { let hub: TestHub let scope: Scope let dispatchQueue = TestSentryDispatchQueueWrapper() - let timerWrapper = TestSentryNSTimerWrapper() + let timerFactory = TestSentryNSTimerFactory() let transactionName = "Some Transaction" let transactionOperation = "ui.load" @@ -91,7 +91,7 @@ class SentryTracerTests: XCTestCase { customSamplingContext: [:], configuration: SentryTracerConfiguration(block: { $0.waitForChildren = waitForChildren - $0.timerWrapper = self.timerWrapper + $0.timerFactory = self.timerFactory })) return tracer } @@ -165,7 +165,7 @@ class SentryTracerTests: XCTestCase { child3.finish() - fixture.timerWrapper.fire() + fixture.timerFactory.fire() assertOneTransactionCaptured(sut) @@ -197,7 +197,7 @@ class SentryTracerTests: XCTestCase { child3.finish() - fixture.timerWrapper.fire() + fixture.timerFactory.fire() XCTAssertEqual(sut.status, .undefined) XCTAssertEqual(child1.status, .undefined) @@ -209,7 +209,7 @@ class SentryTracerTests: XCTestCase { let sut = fixture.getSut() sut.finish() - XCTAssertFalse(fixture.timerWrapper.overrides.timer.isValid) + XCTAssertFalse(fixture.timerFactory.overrides.timer.isValid) } func testDeadlineTimer_MultipleSpansFinishedInParallel() { @@ -224,7 +224,7 @@ class SentryTracerTests: XCTestCase { func testFinish_CheckDefaultStatus() { let sut = fixture.getSut() sut.finish() - fixture.timerWrapper.fire() + fixture.timerFactory.fire() XCTAssertEqual(sut.status, .ok) } From fc0d619812e63f299483239d19f0f5de1feb5d3f Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 23 Jun 2023 16:07:49 -0800 Subject: [PATCH 2/2] fix build --- Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift b/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift index 6c0ad88bc92..8f610b26c32 100644 --- a/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift +++ b/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift @@ -43,13 +43,13 @@ class SentryProfilerSwiftTests: XCTestCase { options.profilesSampleRate = 1.0 options.tracesSampleRate = 1.0 - SentryDependencyContainer.sharedInstance().systemWrapper = systemWrapper - SentryDependencyContainer.sharedInstance().processInfoWrapper = processInfoWrapper + SentryProfiler.useSystemWrapper(systemWrapper) + SentryProfiler.useProcessInfoWrapper(processInfoWrapper) dispatchFactory.vendedSourceHandler = { eventHandler in self.metricTimerWrapper = eventHandler } - SentryDependencyContainer.sharedInstance().dispatchFactory = dispatchFactory - SentryDependencyContainer.sharedInstance().timerFactory = timeoutTimerFactory + SentryProfiler.useDispatchFactory(dispatchFactory) + SentryProfiler.useTimeoutTimerWrapper(timeoutTimerWrapper) systemWrapper.overrides.cpuUsagePerCore = mockCPUUsages.map { NSNumber(value: $0) } processInfoWrapper.overrides.processorCount = UInt(mockCPUUsages.count)