Merge all copies of RUN_RUNLOOP_WHILE in UIExplorerUnitTests

Reviewed By: mhorowitz

Differential Revision: D4921344

fbshipit-source-id: 8b00acba108e46c55374df54a027015d4327d683
This commit is contained in:
Pieter De Baets 2017-04-21 08:16:17 -07:00 committed by Facebook Github Bot
parent 59378f71db
commit 6b19419cdb
8 changed files with 42 additions and 100 deletions

View File

@ -15,19 +15,12 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTBridge+Private.h> #import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h> #import <React/RCTBridge.h>
#import <React/RCTModuleMethod.h> #import <React/RCTModuleMethod.h>
#import <React/RCTRootView.h> #import <React/RCTRootView.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
} \
}
@interface RCTJavaScriptContext : NSObject @interface RCTJavaScriptContext : NSObject
@property (nonatomic, assign, readonly) JSGlobalContextRef ctx; @property (nonatomic, assign, readonly) JSGlobalContextRef ctx;
@ -131,7 +124,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a
(void)bridge; (void)bridge;
} }
RUN_RUNLOOP_WHILE(module.isValid) RCT_RUN_RUNLOOP_WHILE(module.isValid)
XCTAssertFalse(module.isValid, @"AllocationTestModule should have been invalidated by the bridge"); XCTAssertFalse(module.isValid, @"AllocationTestModule should have been invalidated by the bridge");
} }
@ -150,7 +143,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a
(void)bridge; (void)bridge;
} }
RUN_RUNLOOP_WHILE(weakModule) RCT_RUN_RUNLOOP_WHILE(weakModule)
XCTAssertNil(weakModule, @"AllocationTestModule should have been deallocated"); XCTAssertNil(weakModule, @"AllocationTestModule should have been deallocated");
} }
@ -163,7 +156,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a
XCTAssertNotNil(method, @"RCTModuleMethod should have been created"); XCTAssertNotNil(method, @"RCTModuleMethod should have been created");
} }
RUN_RUNLOOP_WHILE(weakMethod) RCT_RUN_RUNLOOP_WHILE(weakMethod)
XCTAssertNil(weakMethod, @"RCTModuleMethod should have been deallocated"); XCTAssertNil(weakMethod, @"RCTModuleMethod should have been deallocated");
} }
@ -175,7 +168,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a
__weak UIView *rootContentView; __weak UIView *rootContentView;
@autoreleasepool { @autoreleasepool {
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"" initialProperties:nil]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"" initialProperties:nil];
RUN_RUNLOOP_WHILE(!(rootContentView = [rootView valueForKey:@"contentView"])) RCT_RUN_RUNLOOP_WHILE(!(rootContentView = [rootView valueForKey:@"contentView"]))
XCTAssertTrue(rootContentView.userInteractionEnabled, @"RCTContentView should be valid"); XCTAssertTrue(rootContentView.userInteractionEnabled, @"RCTContentView should be valid");
(void)rootView; (void)rootView;
} }
@ -197,7 +190,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a
[bridge reload]; [bridge reload];
} }
RUN_RUNLOOP_WHILE(batchedBridge != nil) RCT_RUN_RUNLOOP_WHILE(batchedBridge != nil)
XCTAssertNotNil(bridge, @"RCTBridge should not have been deallocated"); XCTAssertNotNil(bridge, @"RCTBridge should not have been deallocated");
XCTAssertNil(batchedBridge, @"RCTBatchedBridge should have been deallocated"); XCTAssertNil(batchedBridge, @"RCTBatchedBridge should have been deallocated");
@ -209,7 +202,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a
bridge = nil; bridge = nil;
} }
RUN_RUNLOOP_WHILE(batchedBridge != nil); RCT_RUN_RUNLOOP_WHILE(batchedBridge != nil);
XCTAssertNil(batchedBridge); XCTAssertNil(batchedBridge);
} }

View File

@ -15,24 +15,13 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTBridge+Private.h> #import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h> #import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h> #import <React/RCTBridgeModule.h>
#import <React/RCTJavaScriptExecutor.h> #import <React/RCTJavaScriptExecutor.h>
#import <React/RCTUtils.h> #import <React/RCTUtils.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION)) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
if ([timeout timeIntervalSinceNow] <= 0) { \
XCTFail(@"Runloop timed out before condition was met"); \
break; \
} \
} \
}
static const NSUInteger kNameIndex = 0; static const NSUInteger kNameIndex = 0;
static const NSUInteger kConstantsIndex = 1; static const NSUInteger kConstantsIndex = 1;
static const NSUInteger kMethodsIndex = 2; static const NSUInteger kMethodsIndex = 2;
@ -183,14 +172,14 @@ RCT_EXPORT_MODULE(TestModule)
_testMethodCalled = NO; _testMethodCalled = NO;
[_bridge invalidate]; [_bridge invalidate];
RUN_RUNLOOP_WHILE(_jsExecutor.isValid); RCT_RUN_RUNLOOP_WHILE(_jsExecutor.isValid);
_bridge = nil; _bridge = nil;
} }
- (void)testHookRegistration - (void)testHookRegistration
{ {
NSString *injectedStuff; NSString *injectedStuff;
RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); RCT_RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"]));
XCTAssertNotNil(injectedStuff); XCTAssertNotNil(injectedStuff);
__block NSNumber *testModuleID = nil; __block NSNumber *testModuleID = nil;
@ -217,7 +206,7 @@ RCT_EXPORT_MODULE(TestModule)
- (void)testCallNativeMethod - (void)testCallNativeMethod
{ {
NSString *injectedStuff; NSString *injectedStuff;
RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); RCT_RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"]));
XCTAssertNotNil(injectedStuff); XCTAssertNotNil(injectedStuff);
__block NSNumber *testModuleID = nil; __block NSNumber *testModuleID = nil;
@ -249,7 +238,7 @@ RCT_EXPORT_MODULE(TestModule)
- (void)testCallUnregisteredModuleMethod - (void)testCallUnregisteredModuleMethod
{ {
NSString *injectedStuff; NSString *injectedStuff;
RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); RCT_RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"]));
XCTAssertNotNil(injectedStuff); XCTAssertNotNil(injectedStuff);
__block NSNumber *testModuleID = nil; __block NSNumber *testModuleID = nil;

View File

@ -14,22 +14,11 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTUIManager.h> #import <React/RCTUIManager.h>
#import <React/RCTView.h> #import <React/RCTView.h>
#import <React/RCTViewManager.h> #import <React/RCTViewManager.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION)) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
if ([timeout timeIntervalSinceNow] <= 0) { \
XCTFail(@"Runloop timed out before condition was met"); \
break; \
} \
} \
}
@interface RCTUIManager () @interface RCTUIManager ()
- (void)createView:(NSNumber *)reactTag - (void)createView:(NSNumber *)reactTag
@ -99,7 +88,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView)
_bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"UIExplorerUnitTestsBundle" withExtension:@"js"] _bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"UIExplorerUnitTestsBundle" withExtension:@"js"]
moduleProvider:nil moduleProvider:nil
launchOptions:nil]; launchOptions:nil];
RUN_RUNLOOP_WHILE(_bridge.isLoading); RCT_RUN_RUNLOOP_WHILE(_bridge.isLoading);
} }
- (void)testSetProps - (void)testSetProps
@ -123,7 +112,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView)
[uiManager setNeedsLayout]; [uiManager setNeedsLayout];
}); });
RUN_RUNLOOP_WHILE(view == nil); RCT_RUN_RUNLOOP_WHILE(view == nil);
} }
- (void)testResetProps - (void)testResetProps
@ -153,7 +142,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView)
[uiManager setNeedsLayout]; [uiManager setNeedsLayout];
}); });
RUN_RUNLOOP_WHILE(view == nil); RCT_RUN_RUNLOOP_WHILE(view == nil);
} }
- (void)testResetBackgroundColor - (void)testResetBackgroundColor
@ -177,7 +166,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView)
[uiManager setNeedsLayout]; [uiManager setNeedsLayout];
}); });
RUN_RUNLOOP_WHILE(view == nil); RCT_RUN_RUNLOOP_WHILE(view == nil);
} }
@end @end

View File

@ -14,22 +14,11 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTBridge+JavaScriptCore.h> #import <React/RCTBridge+JavaScriptCore.h>
#import <React/RCTBridge.h> #import <React/RCTBridge.h>
#import <React/RCTDevMenu.h> #import <React/RCTDevMenu.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION)) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
if ([timeout timeIntervalSinceNow] <= 0) { \
XCTFail(@"Runloop timed out before condition was met"); \
break; \
} \
} \
}
typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action);
@interface RCTDevMenu () @interface RCTDevMenu ()
@ -56,7 +45,7 @@ typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action);
moduleProvider:nil moduleProvider:nil
launchOptions:nil]; launchOptions:nil];
RUN_RUNLOOP_WHILE(_bridge.isLoading); RCT_RUN_RUNLOOP_WHILE(_bridge.isLoading);
} }
- (void)testShowCreatingActionSheet - (void)testShowCreatingActionSheet

View File

@ -14,17 +14,10 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTNetworking.h> #import <React/RCTNetworking.h>
#import <React/RCTUtils.h> #import <React/RCTUtils.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
} \
}
extern BOOL RCTIsGzippedData(NSData *data); extern BOOL RCTIsGzippedData(NSData *data);
@interface RCTNetworking (Private) @interface RCTNetworking (Private)
@ -83,7 +76,7 @@ extern BOOL RCTIsGzippedData(NSData *data);
request = _request; request = _request;
}]; }];
RUN_RUNLOOP_WHILE(request == nil); RCT_RUN_RUNLOOP_WHILE(request == nil);
XCTAssertNotNil(request); XCTAssertNotNil(request);
XCTAssertNotNil(request.HTTPBody); XCTAssertNotNil(request.HTTPBody);

View File

@ -15,6 +15,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTBridge+Private.h> #import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h> #import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h> #import <React/RCTBridgeModule.h>
@ -22,18 +23,6 @@
#import <React/RCTUIManager.h> #import <React/RCTUIManager.h>
#import <React/RCTViewManager.h> #import <React/RCTViewManager.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION)) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
if ([timeout timeIntervalSinceNow] <= 0) { \
XCTFail(@"Runloop timed out before condition was met"); \
break; \
} \
} \
}
@interface RCTTestViewManager : RCTViewManager @interface RCTTestViewManager : RCTViewManager
@end @end
@ -127,7 +116,7 @@ RCT_EXPORT_MODULE()
- (void)testViewManagerNotInitializedBeforeSetBridgeModule - (void)testViewManagerNotInitializedBeforeSetBridgeModule
{ {
RUN_RUNLOOP_WHILE(!_notificationObserver.didDetectViewManagerInit); RCT_RUN_RUNLOOP_WHILE(!_notificationObserver.didDetectViewManagerInit);
} }
@end @end

View File

@ -15,25 +15,13 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTBridge+Private.h> #import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h> #import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h> #import <React/RCTBridgeModule.h>
#import <React/RCTJavaScriptExecutor.h> #import <React/RCTJavaScriptExecutor.h>
#import <React/RCTUtils.h> #import <React/RCTUtils.h>
#define RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION)) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
if ([timeout timeIntervalSinceNow] <= 0) { \
XCTFail(@"Runloop timed out before condition was met"); \
break; \
} \
} \
}
@interface RCTTestInjectedModule : NSObject <RCTBridgeModule> @interface RCTTestInjectedModule : NSObject <RCTBridgeModule>
@end @end
@ -205,13 +193,13 @@ RCT_EXPORT_MODULE()
XCTAssertEqual(_injectedModule, [_bridge moduleForClass:[RCTTestInjectedModule class]]); XCTAssertEqual(_injectedModule, [_bridge moduleForClass:[RCTTestInjectedModule class]]);
XCTAssertEqual(_injectedModule.bridge, _bridge.batchedBridge); XCTAssertEqual(_injectedModule.bridge, _bridge.batchedBridge);
XCTAssertNotNil(_injectedModule.methodQueue); XCTAssertNotNil(_injectedModule.methodQueue);
RUN_RUNLOOP_WHILE(!_injectedModuleInitNotificationSent); RCT_RUN_RUNLOOP_WHILE(!_injectedModuleInitNotificationSent);
XCTAssertTrue(_injectedModuleInitNotificationSent); XCTAssertTrue(_injectedModuleInitNotificationSent);
} }
- (void)testCustomInitModuleInitializedAtBridgeStartup - (void)testCustomInitModuleInitializedAtBridgeStartup
{ {
RUN_RUNLOOP_WHILE(!_customInitModuleNotificationSent); RCT_RUN_RUNLOOP_WHILE(!_customInitModuleNotificationSent);
XCTAssertTrue(_customInitModuleNotificationSent); XCTAssertTrue(_customInitModuleNotificationSent);
RCTTestCustomInitModule *module = [_bridge moduleForClass:[RCTTestCustomInitModule class]]; RCTTestCustomInitModule *module = [_bridge moduleForClass:[RCTTestCustomInitModule class]];
XCTAssertTrue(module.initializedOnMainQueue); XCTAssertTrue(module.initializedOnMainQueue);
@ -228,7 +216,7 @@ RCT_EXPORT_MODULE()
module = [self->_bridge moduleForClass:[RCTTestCustomSetBridgeModule class]]; module = [self->_bridge moduleForClass:[RCTTestCustomSetBridgeModule class]];
}); });
RUN_RUNLOOP_WHILE(!module); RCT_RUN_RUNLOOP_WHILE(!module);
XCTAssertTrue(_customSetBridgeModuleNotificationSent); XCTAssertTrue(_customSetBridgeModuleNotificationSent);
XCTAssertFalse(module.setBridgeOnMainQueue); XCTAssertFalse(module.setBridgeOnMainQueue);
XCTAssertEqual(module.bridge, _bridge.batchedBridge); XCTAssertEqual(module.bridge, _bridge.batchedBridge);
@ -237,10 +225,10 @@ RCT_EXPORT_MODULE()
- (void)testExportConstantsModuleInitializedAtBridgeStartup - (void)testExportConstantsModuleInitializedAtBridgeStartup
{ {
RUN_RUNLOOP_WHILE(!_exportConstantsModuleNotificationSent); RCT_RUN_RUNLOOP_WHILE(!_exportConstantsModuleNotificationSent);
XCTAssertTrue(_exportConstantsModuleNotificationSent); XCTAssertTrue(_exportConstantsModuleNotificationSent);
RCTTestExportConstantsModule *module = [_bridge moduleForClass:[RCTTestExportConstantsModule class]]; RCTTestExportConstantsModule *module = [_bridge moduleForClass:[RCTTestExportConstantsModule class]];
RUN_RUNLOOP_WHILE(!module.exportedConstants); RCT_RUN_RUNLOOP_WHILE(!module.exportedConstants);
XCTAssertTrue(module.exportedConstants); XCTAssertTrue(module.exportedConstants);
XCTAssertTrue(module.exportedConstantsOnMainQueue); XCTAssertTrue(module.exportedConstantsOnMainQueue);
XCTAssertEqual(module.bridge, _bridge.batchedBridge); XCTAssertEqual(module.bridge, _bridge.batchedBridge);
@ -256,7 +244,7 @@ RCT_EXPORT_MODULE()
module = [self->_bridge moduleForClass:[RCTLazyInitModule class]]; module = [self->_bridge moduleForClass:[RCTLazyInitModule class]];
}); });
RUN_RUNLOOP_WHILE(!module); RCT_RUN_RUNLOOP_WHILE(!module);
XCTAssertTrue(_lazyInitModuleNotificationSent); XCTAssertTrue(_lazyInitModuleNotificationSent);
XCTAssertFalse(_lazyInitModuleNotificationSentOnMainQueue); XCTAssertFalse(_lazyInitModuleNotificationSentOnMainQueue);
XCTAssertNotNil(module); XCTAssertNotNil(module);

View File

@ -15,6 +15,18 @@
#define FB_REFERENCE_IMAGE_DIR "" #define FB_REFERENCE_IMAGE_DIR ""
#endif #endif
#define RCT_RUN_RUNLOOP_WHILE(CONDITION) \
{ \
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \
while ((CONDITION)) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
if ([timeout timeIntervalSinceNow] <= 0) { \
XCTFail(@"Runloop timed out before condition was met"); \
break; \
} \
} \
}
/** /**
* Use the RCTInitRunnerForApp macro for typical usage. See FBSnapshotTestCase.h for more information * Use the RCTInitRunnerForApp macro for typical usage. See FBSnapshotTestCase.h for more information
* on how to configure the snapshotting system. * on how to configure the snapshotting system.