Skip to content

Commit

Permalink
NR-323013 trying to fix the flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbruin-NR committed Dec 16, 2024
1 parent 87338c4 commit 3004d47
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ - (void)testEventRemoval {

XCTestExpectation *waitForInitialWriteExpectation = [self expectationWithDescription:@"Waiting for the first time the file is written"];
PersistentEventStore *sut = [[PersistentEventStore alloc] initWithFilename:testFilename
andMinimumDelay:1];
andMinimumDelay:.025];

NSError *error = nil;

Expand Down
75 changes: 6 additions & 69 deletions Tests/Unit-Tests/NewRelicAgentTests/Uncategorized/NRLoggerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ - (void) tearDown

- (void) testNRLogger {

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

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

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

[NewRelic logInfo: @"Info Log..."];
[NewRelic logError: @"Error Log..."];
[NewRelic logVerbose:@"Verbose Log..."];
Expand All @@ -93,20 +81,9 @@ - (void) testNRLogger {
@"additionalAttribute2": @"attribute2"
}];

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(), ^{
[delayExpectation2 fulfill];
});

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

NSError* error;
NSString *path = [NRLogger logFilePath];
NSData* logData = [NRLogger logFileData:&error];
if(error){
NSLog(@"%@", error.localizedDescription);
Expand Down Expand Up @@ -174,17 +151,7 @@ - (void) testRemoteLogLevels {
// Set the remote log level to Debug.
[NRLogger setRemoteLogLevel:NRLogLevelDebug];

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

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

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

// Seven messages should reach the remote log file for upload.

Expand All @@ -201,17 +168,7 @@ - (void) testRemoteLogLevels {
@"additionalAttribute2": @"attribute2"
}];

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(), ^{
[delayExpectation2 fulfill];
});

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

NSError* error;
NSData* logData = [NRLogger logFileData:&error];
Expand Down Expand Up @@ -264,17 +221,7 @@ - (void) testLocalLogLevels {
// Set the remote log level to Info.
[NRLogger setRemoteLogLevel:NRLogLevelInfo];

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

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

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

// Seven messages should reach the remote log file for upload.

Expand All @@ -291,17 +238,7 @@ - (void) testLocalLogLevels {
@"additionalAttribute2": @"attribute2"
}];

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(), ^{
[delayExpectation2 fulfill];
});

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

NSError* error;
NSData* logData = [NRLogger logFileData:&error];
Expand Down Expand Up @@ -352,7 +289,7 @@ - (void) testAutoCollectedLogs {
[NRLogger setRemoteLogLevel:NRLogLevelDebug];
XCTAssertTrue([NRAutoLogCollector redirectStandardOutputAndError]);

sleep(5);
sleep(1);

// Three messages should reach the remote log file for upload.
NSLog(@"NSLog Test \n\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ -(void)test {
[[NRMAStartTimer sharedInstance] createDurationMetric];

[NRMASupportMetricHelper processDeferredMetrics];
sleep(1);
[NRMATaskQueue synchronousDequeue];

NRMANamedValueMeasurement* measurement = ((NRMANamedValueMeasurement*)helper.result);
Expand Down

0 comments on commit 3004d47

Please sign in to comment.