Fix GrpcIosTestUITests flake and add some more testcases.

Added testcases for switching between apps, and turning wifi on/off.
Also fixed test flakes where UI button presses weren't working.
pull/18330/head
Prashant Jaikumar 6 years ago
parent 597714b6a7
commit 8b10d5faa7
  1. 101
      src/objective-c/manual_tests/GrpcIosTest.xcodeproj/xcshareddata/xcschemes/GrpcIosTest.xcscheme
  2. 225
      src/objective-c/manual_tests/GrpcIosTestUITests/GrpcIosTestUITests.m
  3. 55
      src/objective-c/manual_tests/Main.storyboard
  4. 60
      src/objective-c/manual_tests/ViewController.m

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EDA907A220DF0BC0046D27A"
BuildableName = "GrpcIosTest.app"
BlueprintName = "GrpcIosTest"
ReferencedContainer = "container:GrpcIosTest.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B0C18CA3222DEF140002B502"
BuildableName = "GrpcIosTestUITests.xctest"
BlueprintName = "GrpcIosTestUITests"
ReferencedContainer = "container:GrpcIosTest.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EDA907A220DF0BC0046D27A"
BuildableName = "GrpcIosTest.app"
BlueprintName = "GrpcIosTest"
ReferencedContainer = "container:GrpcIosTest.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EDA907A220DF0BC0046D27A"
BuildableName = "GrpcIosTest.app"
BlueprintName = "GrpcIosTest"
ReferencedContainer = "container:GrpcIosTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EDA907A220DF0BC0046D27A"
BuildableName = "GrpcIosTest.app"
BlueprintName = "GrpcIosTest"
ReferencedContainer = "container:GrpcIosTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

@ -19,6 +19,7 @@
#import <XCTest/XCTest.h>
NSTimeInterval const kWaitTime = 30;
int const kNumIterations = 1;
@interface GrpcIosTestUITests : XCTestCase
@end
@ -32,16 +33,27 @@ NSTimeInterval const kWaitTime = 30;
self.continueAfterFailure = NO;
[[[XCUIApplication alloc] init] launch];
testApp = [[XCUIApplication alloc] initWithBundleIdentifier:@"io.grpc.GrpcIosTest"];
[testApp activate];
// Reset RPC counter
[self pressButton:@"Reset counter"];
settingsApp = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.Preferences"];
[settingsApp activate];
[NSThread sleepForTimeInterval:1];
// Go back to the first page of Settings.
XCUIElement *backButton = settingsApp.navigationBars.buttons.firstMatch;
while (backButton.exists) {
while (backButton.exists && backButton.isHittable) {
NSLog(@"Tapping back button");
[backButton tap];
}
XCTAssert([settingsApp.navigationBars[@"Settings"] waitForExistenceWithTimeout:kWaitTime]);
NSLog(@"Turning off airplane mode");
// Turn off airplane mode
[self setAirplaneMode:NO];
// Turn on wifi
NSLog(@"Turning on wifi");
[self setWifi:YES];
}
- (void)tearDown {
@ -49,14 +61,25 @@ NSTimeInterval const kWaitTime = 30;
- (void)doUnaryCall {
[testApp activate];
[testApp.buttons[@"Unary call"] tap];
[self pressButton:@"Unary call"];
}
- (void)doStreamingCall {
- (void)do10UnaryCalls {
[testApp activate];
[testApp.buttons[@"Start streaming call"] tap];
[testApp.buttons[@"Send Message"] tap];
[testApp.buttons[@"Stop streaming call"] tap];
[self pressButton:@"10 Unary calls"];
}
- (void)pressButton:(NSString *)name {
// Wait for button to be visible
while (![testApp.buttons[name] exists] || ![testApp.buttons[name] isHittable]) {
[NSThread sleepForTimeInterval:1];
}
// Wait until all events in run loop have been processed
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true) == kCFRunLoopRunHandledSource)
;
NSLog(@"Pressing button: %@", name);
[testApp.buttons[name] tap];
}
- (void)expectCallSuccess {
@ -71,41 +94,81 @@ NSTimeInterval const kWaitTime = 30;
[settingsApp activate];
XCUIElement *mySwitch = settingsApp.tables.element.cells.switches[@"Airplane Mode"];
BOOL from = [(NSString *)mySwitch.value boolValue];
NSLog(@"Setting airplane from: %d to: %d", from, to);
if (from != to) {
[mySwitch tap];
// wait for gRPC to detect the change
sleep(10);
// wait for network change to finish
[NSThread sleepForTimeInterval:5];
}
XCTAssert([(NSString *)mySwitch.value boolValue] == to);
}
- (void)setWifi:(BOOL)to {
[settingsApp activate];
[settingsApp.tables.element.cells.staticTexts[@"Wi-Fi"] tap];
XCUIElement *wifiSwitch = settingsApp.tables.cells.switches[@"Wi-Fi"];
BOOL from = [(NSString *)wifiSwitch.value boolValue];
NSLog(@"Setting wifi from: %d to: %d", from, to);
if (from != to) {
[wifiSwitch tap];
// wait for wifi networks to be detected
[NSThread sleepForTimeInterval:10];
}
// Go back to the first page of Settings.
XCUIElement *backButton = settingsApp.navigationBars.buttons.firstMatch;
[backButton tap];
}
- (void)typeText:(NSString *)text inApp:(XCUIApplication *)app {
[app typeText:text];
// Wait until all events in run loop have been processed
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true) == kCFRunLoopRunHandledSource)
;
}
- (int)getRandomNumberBetween:(int)min max:(int)max {
return min + arc4random_uniform((max - min + 1));
}
- (void)testBackgroundBeforeUnaryCall {
- (void)testBackgroundBeforeCall {
NSLog(@"%s", __func__);
// Open test app
[testApp activate];
// Send test app to background
[XCUIDevice.sharedDevice pressButton:XCUIDeviceButtonHome];
sleep(5);
// Wait a bit
int sleepTime = [self getRandomNumberBetween:5 max:10];
NSLog(@"Sleeping for %d seconds", sleepTime);
[NSThread sleepForTimeInterval:sleepTime];
// Bring test app to foreground and make a unary call. Call should succeed
[self doUnaryCall];
[self expectCallSuccess];
}
- (void)testBackgroundBeforeStreamingCall {
// Open test app
- (void)testBackgroundDuringStreamingCall {
NSLog(@"%s", __func__);
// Open test app and start a streaming call
[testApp activate];
[self pressButton:@"Start streaming call"];
// Send test app to background
[XCUIDevice.sharedDevice pressButton:XCUIDeviceButtonHome];
sleep(5);
// Wait a bit
int sleepTime = [self getRandomNumberBetween:5 max:10];
NSLog(@"Sleeping for %d seconds", sleepTime);
[NSThread sleepForTimeInterval:sleepTime];
// Bring test app to foreground and make a streaming call. Call should succeed.
[self doStreamingCall];
[testApp activate];
[self pressButton:@"Send Message"];
[self pressButton:@"Stop streaming call"];
[self expectCallSuccess];
}
- (void)testUnaryCallAfterNetworkFlap {
- (void)testCallAfterNetworkFlap {
NSLog(@"%s", __func__);
// Open test app and make a unary call. Channel to server should be open after this.
[self doUnaryCall];
[self expectCallSuccess];
@ -119,56 +182,150 @@ NSTimeInterval const kWaitTime = 30;
[self expectCallSuccess];
}
- (void)testStreamingCallAfterNetworkFlap {
- (void)testCallWhileNetworkDown {
NSLog(@"%s", __func__);
// Open test app and make a unary call. Channel to server should be open after this.
[self doUnaryCall];
[self expectCallSuccess];
// Toggle airplane mode on and off
// Turn on airplane mode
[self setAirplaneMode:YES];
// Turn off wifi
[self setWifi:NO];
// Unary call should fail
[self doUnaryCall];
[self expectCallFailed];
// Turn off airplane mode
[self setAirplaneMode:NO];
// Turn on wifi
[self setWifi:YES];
[self doStreamingCall];
// Unary call should succeed
[self doUnaryCall];
[self expectCallSuccess];
}
- (void)testUnaryCallWhileNetworkDown {
- (void)testSwitchApp {
NSLog(@"%s", __func__);
// Open test app and make a unary call. Channel to server should be open after this.
[self doUnaryCall];
[self expectCallSuccess];
// Turn on airplane mode
[self setAirplaneMode:YES];
// Send test app to background
[XCUIDevice.sharedDevice pressButton:XCUIDeviceButtonHome];
// Unary call should fail
// Open safari and goto a URL
XCUIApplication *safari =
[[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.mobilesafari"];
[safari activate];
// Ensure that safari is running in the foreground
XCTAssert([safari waitForState:XCUIApplicationStateRunningForeground timeout:5]);
// Move cursor to address bar
[safari.buttons[@"URL"] tap];
// Wait for keyboard to appear
[NSThread sleepForTimeInterval:2];
// Enter URL
[self typeText:@"http://maps.google.com" inApp:safari];
// Presses return key
[self typeText:@"\n" inApp:safari];
// Wait a bit
int sleepTime = [self getRandomNumberBetween:5 max:10];
NSLog(@"Sleeping for %d seconds", sleepTime);
[NSThread sleepForTimeInterval:sleepTime];
// Make another unary call
[self doUnaryCall];
[self expectCallSuccess];
}
- (void)testNetworkFlapDuringStreamingCall {
NSLog(@"%s", __func__);
// Open test app and make a unary call. Channel to server should be open after this.
[self doUnaryCall];
[self expectCallSuccess];
// Start streaming call and send a message
[self pressButton:@"Start streaming call"];
[self pressButton:@"Send Message"];
// Toggle network on and off
[self setAirplaneMode:YES];
[self setWifi:NO];
[self setAirplaneMode:NO];
[self setWifi:YES];
[testApp activate];
// We expect the call to have failed because the network flapped
[self expectCallFailed];
}
// Turn off airplane mode
- (void)testConcurrentCalls {
NSLog(@"%s", __func__);
// Press button to start 10 unary calls
[self do10UnaryCalls];
// Toggle airplane mode on and off
[self setAirplaneMode:YES];
[self setAirplaneMode:NO];
// Unary call should succeed
// 10 calls should have completed
[testApp activate];
XCTAssert([testApp.staticTexts[@"Calls completed: 10"] waitForExistenceWithTimeout:kWaitTime]);
}
- (void)invokeTest {
for (int i = 0; i < kNumIterations; i++) {
[super invokeTest];
}
}
- (void)testUnaryCallTurnOffWifi {
NSLog(@"%s", __func__);
// Open test app and make a unary call. Channel to server should be open after this.
[self doUnaryCall];
[self expectCallSuccess];
// Turn off wifi
[self setWifi:NO];
// Phone should switch to cellular connection, call should succeed
[self doUnaryCall];
[self expectCallSuccess];
// Turn on wifi
[self setWifi:YES];
// Call should succeed after turning wifi back on
[self doUnaryCall];
[self expectCallSuccess];
}
- (void)testStreamingCallWhileNetworkDown {
- (void)testStreamingCallTurnOffWifi {
NSLog(@"%s", __func__);
// Open test app and make a unary call. Channel to server should be open after this.
[self doUnaryCall];
[self expectCallSuccess];
// Turn on airplane mode
[self setAirplaneMode:YES];
// Start streaming call and send a message
[self pressButton:@"Start streaming call"];
[self pressButton:@"Send Message"];
// Streaming call should fail
[self doStreamingCall];
// Turn off wifi
[self setWifi:NO];
// Phone should switch to cellular connection, this results in the call failing
[testApp activate];
[self pressButton:@"Stop streaming call"];
[self expectCallFailed];
// Turn off airplane mode
[self setAirplaneMode:NO];
// Turn on wifi
[self setWifi:YES];
// Unary call should succeed
[self doStreamingCall];
// Call should succeed after turning wifi back on
[self doUnaryCall];
[self expectCallSuccess];
}
@end

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -26,16 +26,8 @@
<action selector="tapStreamingCallStart:" destination="BYZ-38-t0r" eventType="touchUpInside" id="6tF-9u-Gew"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dxG-ib-Xoa">
<rect key="frame" x="197" y="221" width="132" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Stop streaming call"/>
<connections>
<action selector="tapStreamingCallStop:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QLQ-yw-wlZ"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ay7-K7-Lez">
<rect key="frame" x="48" y="71" width="69" height="30"/>
<rect key="frame" x="35" y="71" width="69" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Unary call"/>
<connections>
@ -43,13 +35,51 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Sq5-O5-fiK">
<rect key="frame" x="213" y="147" width="101" height="30"/>
<rect key="frame" x="196" y="147" width="101" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Send Message"/>
<connections>
<action selector="tapStreamingCallSend:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Qz0-PB-akd"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7JI-bR-X8r">
<rect key="frame" x="134" y="323" width="98" height="56"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" tag="2" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Calls completed: 0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Wwu-kV-w7R">
<rect key="frame" x="128" y="418" width="180" height="56"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="q8d-Mi-SAJ">
<rect key="frame" x="35" y="147" width="96" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="10 Unary calls"/>
<connections>
<action selector="tap10UnaryCalls:" destination="BYZ-38-t0r" eventType="touchUpInside" id="pY2-Rq-hVn"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Csm-o1-8eh">
<rect key="frame" x="35" y="221" width="96" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Reset counter"/>
<connections>
<action selector="resetCounter:" destination="BYZ-38-t0r" eventType="touchUpInside" id="InY-SX-R6H"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dxG-ib-Xoa">
<rect key="frame" x="196" y="221" width="132" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Stop streaming call"/>
<connections>
<action selector="tapStreamingCallStop:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QLQ-yw-wlZ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
@ -57,6 +87,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="128.80000000000001" y="132.68365817091455"/>
</scene>
</scenes>
</document>

@ -27,33 +27,36 @@ NSString *const kRemoteHost = @"grpc-test.sandbox.googleapis.com";
const int32_t kMessageSize = 100;
@interface ViewController : UIViewController<GRPCProtoResponseHandler>
@property(strong, nonatomic) UILabel *fromLabel;
@property(strong, nonatomic) UILabel *callStatusLabel;
@property(strong, nonatomic) UILabel *callCountLabel;
@end
@implementation ViewController {
RMTTestService *_service;
dispatch_queue_t _dispatchQueue;
GRPCStreamingProtoCall *_call;
int _calls_completed;
}
- (instancetype)init {
self = [super init];
_calls_completed = 0;
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
_fromLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 500, 200, 20)];
_fromLabel.textColor = [UIColor blueColor];
_fromLabel.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_fromLabel];
_callStatusLabel = (UILabel *)[self.view viewWithTag:1];
_callCountLabel = (UILabel *)[self.view viewWithTag:2];
}
- (IBAction)tapUnaryCall:(id)sender {
- (void)startUnaryCall {
if (_service == nil) {
_service = [RMTTestService serviceWithHost:kRemoteHost];
}
self->_fromLabel.text = @"";
dispatch_async(dispatch_get_main_queue(), ^{
self->_callStatusLabel.text = @"";
});
// Set up request proto message
RMTSimpleRequest *request = [RMTSimpleRequest message];
@ -63,14 +66,43 @@ const int32_t kMessageSize = 100;
GRPCUnaryProtoCall *call =
[_service unaryCallWithMessage:request responseHandler:self callOptions:nil];
[call start];
}
- (IBAction)tapUnaryCall:(id)sender {
NSLog(@"In tapUnaryCall");
[self startUnaryCall];
}
- (IBAction)tap10UnaryCalls:(id)sender {
NSLog(@"In tap10UnaryCalls");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
// Background thread
for (int i = 0; i < 10; ++i) {
[self startUnaryCall];
[NSThread sleepForTimeInterval:0.5];
}
});
}
- (IBAction)resetCounter:(id)sender {
_calls_completed = 0;
dispatch_async(dispatch_get_main_queue(), ^{
self->_callCountLabel.text =
[NSString stringWithFormat:@"Calls completed: %d", self->_calls_completed];
self->_callStatusLabel.text = @"";
});
}
- (IBAction)tapStreamingCallStart:(id)sender {
NSLog(@"In tapStreamingCallStart");
if (_service == nil) {
_service = [RMTTestService serviceWithHost:kRemoteHost];
}
self->_fromLabel.text = @"";
dispatch_async(dispatch_get_main_queue(), ^{
self->_callStatusLabel.text = @"";
});
// Set up request proto message
RMTStreamingOutputCallRequest *request = RMTStreamingOutputCallRequest.message;
@ -83,10 +115,10 @@ const int32_t kMessageSize = 100;
[call start];
_call = call;
// display something to confirm the tester the call is started
NSLog(@"Started streaming call");
}
- (IBAction)tapStreamingCallSend:(id)sender {
NSLog(@"In tapStreamingCallSend");
if (_call == nil) return;
RMTStreamingOutputCallRequest *request = RMTStreamingOutputCallRequest.message;
@ -99,6 +131,7 @@ const int32_t kMessageSize = 100;
}
- (IBAction)tapStreamingCallStop:(id)sender {
NSLog(@"In tapStreamingCallStop");
if (_call == nil) return;
[_call finish];
@ -118,13 +151,18 @@ const int32_t kMessageSize = 100;
NSLog(@"Recv trailing metadata: %@, error: %@", trailingMetadata, error);
if (error == nil) {
dispatch_async(dispatch_get_main_queue(), ^{
self->_fromLabel.text = @"Call done";
self->_callStatusLabel.text = @"Call done";
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
self->_fromLabel.text = @"Call failed";
self->_callStatusLabel.text = @"Call failed";
});
}
++_calls_completed;
dispatch_async(dispatch_get_main_queue(), ^{
self->_callCountLabel.text =
[NSString stringWithFormat:@"Calls completed: %d", self->_calls_completed];
});
}
- (dispatch_queue_t)dispatchQueue {

Loading…
Cancel
Save