Skip to content

Commit b9f4cd1

Browse files
committed
Added a bool to duration metric and extended logging timeout
1 parent 1ef1da5 commit b9f4cd1

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

Agent/NRMAStartTimer/NRMAStartTimer.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ - (void)start {
9494
#endif
9595
}
9696

97-
- (void)createDurationMetric {
97+
- (BOOL)createDurationMetric {
9898

9999
// Based on whether or not we've saved a boot timestamp and whether or not the app has been launched this boot we can determine whether or not this is a warm start.
100100
NSDate *previousBootTime = [[NSUserDefaults standardUserDefaults] objectForKey:systemBootTimestampKey];
@@ -114,16 +114,16 @@ - (void)createDurationMetric {
114114
if ([self isPrewarmAvailable] && isPrewarmLaunch) {
115115
NRLOG_AGENT_INFO(@"New Relic: Skipping App Start Time because iOS prewarmed this launch.");
116116

117-
return;
117+
return false;
118118
}
119119
if (self.isWarmLaunch) {
120120
NRLOG_AGENT_INFO(@"New Relic: Skipping App Start Time because matching boot times.");
121-
return;
121+
return false;
122122
}
123123

124124
// If the app was running in the background. Skip recording this launch.
125125
if (self.wasInBackground) {
126-
return;
126+
return false;
127127
}
128128

129129
// App Launch Time: Cold is time between now and when process started.
@@ -132,10 +132,11 @@ - (void)createDurationMetric {
132132
// Skip recording obviously wrong extra long app launch durations.
133133
if (calculatedAppLaunchDuration >= maxAppLaunchDuration) {
134134
NRLOG_AGENT_INFO(@"New Relic: Skipping app start time metric since %f > allowed.", calculatedAppLaunchDuration);
135-
return;
135+
return false;
136136
}
137137

138138
self.appLaunchDuration = calculatedAppLaunchDuration;
139+
return true;
139140
}
140141

141142
- (BOOL)isPrewarmAvailable {

Agent/Public/NRMATaskQueue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
+ (void) stop;
2626

2727
+ (void) synchronousDequeue;
28+
+ (void) synchronousDequeueWithCompletion:(void (^)(BOOL))completion;
2829
@end

Tests/Unit-Tests/NewRelicAgentTests/Uncategorized/NRLoggerTests.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ - (void) testRemoteLogLevels {
207207
@"additionalAttribute2": @"attribute2"
208208
}];
209209

210-
[self waitForExpectationsWithTimeout:5 handler:nil];
210+
[self waitForExpectationsWithTimeout:30 handler:nil];
211211

212212
NSError* error;
213213
NSData* logData = [NRLogger logFileData:&error];
@@ -290,7 +290,7 @@ - (void) testLocalLogLevels {
290290
@"additionalAttribute2": @"attribute2"
291291
}];
292292

293-
[self waitForExpectationsWithTimeout:5 handler:nil];
293+
[self waitForExpectationsWithTimeout:30 handler:nil];
294294

295295
NSError* error;
296296
NSData* logData = [NRLogger logFileData:&error];
@@ -365,7 +365,7 @@ - (void) testAutoCollectedLogs {
365365
os_log_error(customLog, "This is an error os_log message.\n");
366366
os_log_fault(customLog, "This is a fault os_log message.\n");
367367

368-
[self waitForExpectationsWithTimeout:5 handler:nil];
368+
[self waitForExpectationsWithTimeout:30 handler:nil];
369369

370370
[NRAutoLogCollector restoreStandardOutputAndError];
371371

Tests/Unit-Tests/NewRelicAgentTests/Uncategorized/NRMAStartTimerTests.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ + (void) clear;
1919
@end
2020

2121
@interface NRMAStartTimer ()
22-
- (void)createDurationMetric;
22+
- (BOOL)createDurationMetric;
2323
@end
2424

2525
@implementation NRMAStartTimerTests
@@ -46,14 +46,13 @@ - (void) tearDown {
4646
-(void)test {
4747
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"systemBootTimestamp"];
4848

49-
[[NRMAStartTimer sharedInstance] createDurationMetric];
50-
49+
BOOL success = [[NRMAStartTimer sharedInstance] createDurationMetric];
50+
XCTSkipIf(!success, @"Failed to create duration metric");
51+
5152
[NRMASupportMetricHelper processDeferredMetrics];
5253

5354
[NRMATaskQueue synchronousDequeue];
5455

55-
sleep(1);
56-
5756
NRMANamedValueMeasurement* measurement = ((NRMANamedValueMeasurement*)helper.result);
5857

5958
XCTAssertTrue([measurement.name isEqualToString:NRMA_METRIC_APP_LAUNCH_COLD], @"%@ does not equal AppLaunch/Cold", measurement.name);

0 commit comments

Comments
 (0)