Fix timing issues in RCTLoggingTests.m

Summary:
**Motivation**

If there are any console log messages that come in on initialization (as will happen right now in tvOS), the RCTLoggingTests can fail intermittently.  This change delays the start of the logging test to allow time for initial console messages to come in.
Closes https://github.com/facebook/react-native/pull/10568

Differential Revision: D4087974

Pulled By: bestander

fbshipit-source-id: 2b0f4a88a74bc6121133317dd909d5bd1f10789b
This commit is contained in:
Douglas Lowder 2016-10-27 01:37:06 -07:00 committed by Facebook Github Bot
parent e000b71845
commit bdff1c3f02
2 changed files with 20 additions and 9 deletions

View File

@ -51,14 +51,6 @@
XCTAssertFalse(_bridge.loading);
_logSem = dispatch_semaphore_create(0);
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, __unused NSString *fileName, __unused NSNumber *lineNumber, NSString *message) {
if (source == RCTLogSourceJavaScript) {
self->_lastLogLevel = level;
self->_lastLogSource = source;
self->_lastLogMessage = message;
dispatch_semaphore_signal(self->_logSem);
}
});
}
- (void)tearDown
@ -71,7 +63,21 @@
- (void)testLogging
{
[_bridge enqueueJSCall:@"LoggingTestModule.logToConsole" args:@[@"Invoking console.log"]];
// First console log call will fire after 2.0 sec, to allow for any initial log messages
// that might come in (seeing this in tvOS)
[_bridge enqueueJSCall:@"LoggingTestModule.logToConsoleAfterWait" args:@[@"Invoking console.log",@2000]];
// Spin native layer for 1.9 sec
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.9]];
// Now set the log function to signal the semaphore
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, __unused NSString *fileName, __unused NSNumber *lineNumber, NSString *message) {
if (source == RCTLogSourceJavaScript) {
self->_lastLogLevel = level;
self->_lastLogSource = source;
self->_lastLogMessage = message;
dispatch_semaphore_signal(self->_logSem);
}
});
// Wait for console log to signal the semaphore
dispatch_semaphore_wait(_logSem, DISPATCH_TIME_FOREVER);
XCTAssertEqual(_lastLogLevel, RCTLogLevelInfo);

View File

@ -19,6 +19,11 @@ var LoggingTestModule = {
logToConsole: function(str) {
console.log(str);
},
logToConsoleAfterWait: function(str,timeout_ms) {
setTimeout(function() {
console.log(str);
}, timeout_ms);
},
warning: function(str) {
warning(false, str);
},