Skip to content

Commit

Permalink
Unit test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbruin-NR committed Oct 24, 2024
1 parent 97cffc6 commit c418948
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions Tests/Unit-Tests/NewRelicAgentTests/Uncategorized/NRLoggerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,38 +258,26 @@ - (void) testRemoteLogLevels {
#if !TARGET_OS_WATCH
- (void) testAutoCollectedLogs {
[NRMAFlags enableFeatures: NRFeatureFlag_RedirectStdOutStdErr];
// Set the remote log level to Info.
// Set the remote log level to debug.
[NRLogger setRemoteLogLevel:NRLogLevelDebug];
[NRAutoLogCollector redirectStandardOutputAndError];

XCTestExpectation *delayExpectation1 = [self expectationWithDescription:@"Waiting for Log Queue"];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[delayExpectation1 fulfill];
});

[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {
if (error) {
XCTFail(@"Timeout error");
}
}];

// Three messages should reach the remote log file for upload.
NSLog(@"NSLog Test \n");
NSLog(@"NSLog Test \n\n");
os_log_t customLog = os_log_create("com.agent.tests", "logTest");
// Log messages at different levels
os_log(customLog, "This is a default os_log message.");
os_log_info(customLog, "This is an info os_log message.");
os_log_error(customLog, "This is an error os_log message.");
os_log_fault(customLog, "This is a fault os_log message.");
os_log(customLog, "This is a default os_log message.\n");
os_log_info(customLog, "This is an info os_log message.\n");
os_log_error(customLog, "This is an error os_log message.\n");
os_log_fault(customLog, "This is a fault os_log message.\n");

XCTestExpectation *delayExpectation2 = [self expectationWithDescription:@"Waiting for Log Queue"];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[delayExpectation2 fulfill];
});

[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {
[self waitForExpectationsWithTimeout:8 handler:^(NSError * _Nullable error) {
if (error) {
XCTFail(@"Timeout error");
}
Expand All @@ -315,7 +303,7 @@ - (void) testAutoCollectedLogs {
@{@"message": @"This is an error os_log message."},
@{@"message": @"This is a fault os_log message."},
];
// check for existence of 6 logs.
// check for existence of 5 logs.
int foundCount = 0;
// For each expected message.
for (NSDictionary *dict in expectedValues) {
Expand Down

0 comments on commit c418948

Please sign in to comment.