aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-04-11 18:10:02 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-04-11 18:10:02 -0700
commitc92d90aba2bd1bd710830c781d1e1e4c8adea0ba (patch)
treedb1825d2676e0be8809918378ab2826c24d42f17 /src/objective-c/tests
parente433b56defb450f5815e973da8798512b99c9e51 (diff)
clang-format objective-c files
Diffstat (limited to 'src/objective-c/tests')
-rw-r--r--src/objective-c/tests/Connectivity/ConnectivityTestingApp/ViewController.m58
-rw-r--r--src/objective-c/tests/Connectivity/ConnectivityTestingApp/main.m8
-rw-r--r--src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm42
-rw-r--r--src/objective-c/tests/CronetUnitTests/CronetUnitTests.m169
-rw-r--r--src/objective-c/tests/GRPCClientTests.m411
-rw-r--r--src/objective-c/tests/InteropTests.m395
-rw-r--r--src/objective-c/tests/InteropTestsLocalCleartext.m4
-rw-r--r--src/objective-c/tests/InteropTestsLocalSSL.m10
-rw-r--r--src/objective-c/tests/InteropTestsRemote.m4
-rw-r--r--src/objective-c/tests/InteropTestsRemoteWithCronet/InteropTestsRemoteWithCronet.m5
-rw-r--r--src/objective-c/tests/RxLibraryUnitTests.m41
-rw-r--r--src/objective-c/tests/version.h1
12 files changed, 588 insertions, 560 deletions
diff --git a/src/objective-c/tests/Connectivity/ConnectivityTestingApp/ViewController.m b/src/objective-c/tests/Connectivity/ConnectivityTestingApp/ViewController.m
index f91d2a6b62..88780e39f0 100644
--- a/src/objective-c/tests/Connectivity/ConnectivityTestingApp/ViewController.m
+++ b/src/objective-c/tests/Connectivity/ConnectivityTestingApp/ViewController.m
@@ -20,9 +20,9 @@
#import <GRPCClient/GRPCCall.h>
#import <ProtoRPC/ProtoMethod.h>
+#import <RxLibrary/GRXBufferedPipe.h>
#import <RxLibrary/GRXWriter+Immediate.h>
#import <RxLibrary/GRXWriter+Transformations.h>
-#import <RxLibrary/GRXBufferedPipe.h>
#import "src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h"
@@ -35,8 +35,7 @@ NSString *host = @"grpc-test.sandbox.googleapis.com";
- (void)viewDidLoad {
[super viewDidLoad];
- [GRPCConnectivityMonitor registerObserver:self
- selector:@selector(reachabilityChanged:)];
+ [GRPCConnectivityMonitor registerObserver:self selector:@selector(reachabilityChanged:)];
}
- (void)reachabilityChanged:(NSNotification *)note {
@@ -52,23 +51,21 @@ NSString *host = @"grpc-test.sandbox.googleapis.com";
GRPCProtoMethod *method = [[GRPCProtoMethod alloc] initWithPackage:@"grpc.testing"
service:@"TestService"
method:@"UnaryCall"];
- GRXWriter *loggingRequestWriter =
- [[GRXWriter writerWithValue:[NSData dataWithBytes:bytes length:sizeof(bytes)]]
- map:^id(id value) {
- NSLog(@"Sending request.");
- return value;
- }];
- GRPCCall *call = [[GRPCCall alloc] initWithHost:host
- path:method.HTTPPath
- requestsWriter:loggingRequestWriter];
-
- [call startWithWriteable:[GRXWriteable writeableWithEventHandler:^(BOOL done, id value,
- NSError *error) {
- if (!done) {
- return;
- }
- NSLog(@"Unary call finished with error: %@", error);
- }]];
+ GRXWriter *loggingRequestWriter = [[GRXWriter
+ writerWithValue:[NSData dataWithBytes:bytes length:sizeof(bytes)]] map:^id(id value) {
+ NSLog(@"Sending request.");
+ return value;
+ }];
+ GRPCCall *call =
+ [[GRPCCall alloc] initWithHost:host path:method.HTTPPath requestsWriter:loggingRequestWriter];
+
+ [call startWithWriteable:[GRXWriteable
+ writeableWithEventHandler:^(BOOL done, id value, NSError *error) {
+ if (!done) {
+ return;
+ }
+ NSLog(@"Unary call finished with error: %@", error);
+ }]];
}
- (IBAction)tapStreaming:(id)sender {
@@ -85,17 +82,16 @@ NSString *host = @"grpc-test.sandbox.googleapis.com";
[requestsBuffer writeValue:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
- GRPCCall *call = [[GRPCCall alloc] initWithHost:host
- path:method.HTTPPath
- requestsWriter:requestsBuffer];
-
- [call startWithWriteable:[GRXWriteable writeableWithEventHandler:^(BOOL done, id value,
- NSError *error) {
- if (!done) {
- return;
- }
- NSLog(@"Streaming call finished with error: %@", error);
- }]];
+ GRPCCall *call =
+ [[GRPCCall alloc] initWithHost:host path:method.HTTPPath requestsWriter:requestsBuffer];
+
+ [call startWithWriteable:[GRXWriteable
+ writeableWithEventHandler:^(BOOL done, id value, NSError *error) {
+ if (!done) {
+ return;
+ }
+ NSLog(@"Streaming call finished with error: %@", error);
+ }]];
}
@end
diff --git a/src/objective-c/tests/Connectivity/ConnectivityTestingApp/main.m b/src/objective-c/tests/Connectivity/ConnectivityTestingApp/main.m
index 1642fdb2c6..010789e8ab 100644
--- a/src/objective-c/tests/Connectivity/ConnectivityTestingApp/main.m
+++ b/src/objective-c/tests/Connectivity/ConnectivityTestingApp/main.m
@@ -18,14 +18,14 @@
#import <UIKit/UIKit.h>
-@interface AppDelegate : UIResponder <UIApplicationDelegate>
-@property (strong, nonatomic) UIWindow *window;
+@interface AppDelegate : UIResponder<UIApplicationDelegate>
+@property(strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
@end
-int main(int argc, char * argv[]) {
+int main(int argc, char *argv[]) {
@autoreleasepool {
- return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class));
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class));
}
}
diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm
index 5d384d8fc8..80fa0f4785 100644
--- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm
+++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm
@@ -37,11 +37,11 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
-#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
+#include "src/core/lib/security/credentials/credentials.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -58,7 +58,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data *ffd =
- (fullstack_secure_fixture_data*)gpr_malloc(sizeof(fullstack_secure_fixture_data));
+ (fullstack_secure_fixture_data *)gpr_malloc(sizeof(fullstack_secure_fixture_data));
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "127.0.0.1", port);
@@ -70,9 +70,8 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
return f;
}
-static void process_auth_failure(void *state, grpc_auth_context *ctx,
- const grpc_metadata *md, size_t md_count,
- grpc_process_auth_metadata_done_cb cb,
+static void process_auth_failure(void *state, grpc_auth_context *ctx, const grpc_metadata *md,
+ size_t md_count, grpc_process_auth_metadata_done_cb cb,
void *user_data) {
GPR_ASSERT(state == NULL);
cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL);
@@ -83,27 +82,25 @@ static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
stream_engine *cronetEngine) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
grpc_arg arg;
- arg.key = const_cast<char*>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
+ arg.key = const_cast<char *>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
arg.type = GRPC_ARG_INTEGER;
arg.value.integer = 1;
client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1);
- f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr,
- client_args, NULL);
+ f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr, client_args, NULL);
grpc_channel_args_destroy(client_args);
GPR_ASSERT(f->client != NULL);
}
-static void chttp2_init_server_secure_fullstack(
- grpc_end2end_test_fixture *f, grpc_channel_args *server_args,
- grpc_server_credentials *server_creds) {
+static void chttp2_init_server_secure_fullstack(grpc_end2end_test_fixture *f,
+ grpc_channel_args *server_args,
+ grpc_server_credentials *server_creds) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
if (f->server) {
grpc_server_destroy(f->server);
}
f->server = grpc_server_create(server_args, NULL);
grpc_server_register_completion_queue(f->server, f->cq, NULL);
- GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
- server_creds));
+ GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
@@ -114,8 +111,8 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
gpr_free(ffd);
}
-static void cronet_init_client_simple_ssl_secure_fullstack(
- grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
+static void cronet_init_client_simple_ssl_secure_fullstack(grpc_end2end_test_fixture *f,
+ grpc_channel_args *client_args) {
grpc_core::ExecCtx exec_ctx;
stream_engine *cronetEngine = [Cronet getGlobalEngine];
@@ -128,18 +125,16 @@ static int fail_server_auth_check(grpc_channel_args *server_args) {
size_t i;
if (server_args == NULL) return 0;
for (i = 0; i < server_args->num_args; i++) {
- if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) ==
- 0) {
+ if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == 0) {
return 1;
}
}
return 0;
}
-static void chttp2_init_server_simple_ssl_secure_fullstack(
- grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
- grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key,
- test_server1_cert};
+static void chttp2_init_server_simple_ssl_secure_fullstack(grpc_end2end_test_fixture *f,
+ grpc_channel_args *server_args) {
+ grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
@@ -189,9 +184,8 @@ static char *roots_filename;
[Cronet setHttp2Enabled:YES];
[Cronet enableTestCertVerifierForTesting];
- NSURL *url = [[[NSFileManager defaultManager]
- URLsForDirectory:NSDocumentDirectory
- inDomains:NSUserDomainMask] lastObject];
+ NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
+ inDomains:NSUserDomainMask] lastObject];
NSLog(@"Documents directory: %@", url);
[Cronet start];
[Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES];
diff --git a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m
index 3da7d533b4..a6dfb154a4 100644
--- a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m
+++ b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m
@@ -42,8 +42,7 @@
static void drain_cq(grpc_completion_queue *cq) {
grpc_event ev;
do {
- ev = grpc_completion_queue_next(cq, grpc_timeout_seconds_to_deadline(5),
- NULL);
+ ev = grpc_completion_queue_next(cq, grpc_timeout_seconds_to_deadline(5), NULL);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
@@ -64,9 +63,8 @@ static void drain_cq(grpc_completion_queue *cq) {
[Cronet setHttp2Enabled:YES];
[Cronet setSslKeyLogFileName:@"Documents/key"];
[Cronet enableTestCertVerifierForTesting];
- NSURL *url = [[[NSFileManager defaultManager]
- URLsForDirectory:NSDocumentDirectory
- inDomains:NSUserDomainMask] lastObject];
+ NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
+ inDomains:NSUserDomainMask] lastObject];
NSLog(@"Documents directory: %@", url);
[Cronet start];
[Cronet startNetLogToFile:@"Documents/cronet_netlog.json" logBytes:YES];
@@ -88,8 +86,8 @@ void init_ssl(void) {
void cleanup_ssl(void) { EVP_cleanup(); }
-int alpn_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen,
- const unsigned char *in, unsigned int inlen, void *arg) {
+int alpn_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in,
+ unsigned int inlen, void *arg) {
// Always select "h2" as the ALPN protocol to be used
*out = (const unsigned char *)"h2";
*outlen = 2;
@@ -98,16 +96,14 @@ int alpn_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen,
void init_ctx(SSL_CTX *ctx) {
// Install server certificate
- BIO *pem = BIO_new_mem_buf((void *)test_server1_cert,
- (int)strlen(test_server1_cert));
+ BIO *pem = BIO_new_mem_buf((void *)test_server1_cert, (int)strlen(test_server1_cert));
X509 *cert = PEM_read_bio_X509_AUX(pem, NULL, NULL, (char *)"");
SSL_CTX_use_certificate(ctx, cert);
X509_free(cert);
BIO_free(pem);
// Install server private key
- pem =
- BIO_new_mem_buf((void *)test_server1_key, (int)strlen(test_server1_key));
+ pem = BIO_new_mem_buf((void *)test_server1_key, (int)strlen(test_server1_key));
EVP_PKEY *key = PEM_read_bio_PrivateKey(pem, NULL, NULL, (char *)"");
SSL_CTX_use_PrivateKey(ctx, key);
EVP_PKEY_free(key);
@@ -128,7 +124,7 @@ unsigned int parse_h2_length(const char *field) {
grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *args) {
grpc_arg arg;
- arg.key = const_cast<char*>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
+ arg.key = const_cast<char *>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
arg.type = GRPC_ARG_INTEGER;
arg.value.integer = 1;
return grpc_channel_args_copy_and_add(args, &arg, 1);
@@ -136,10 +132,8 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
- (void)testInternalError {
grpc_call *c;
- grpc_slice request_payload_slice =
- grpc_slice_from_copied_string("hello world");
- grpc_byte_buffer *request_payload =
- grpc_raw_byte_buffer_create(&request_payload_slice, 1);
+ grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"),
grpc_slice_from_static_string("val1"),
@@ -156,8 +150,7 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
stream_engine *cronetEngine = [Cronet getGlobalEngine];
grpc_channel_args *client_args = add_disable_client_authority_filter_args(NULL);
- grpc_channel *client =
- grpc_cronet_secure_channel_create(cronetEngine, addr, client_args, NULL);
+ grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, client_args, NULL);
grpc_channel_args_destroy(client_args);
cq_verifier *cqv = cq_verifier_create(cq);
@@ -173,8 +166,7 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
grpc_slice details;
c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
- grpc_slice_from_static_string("/foo"), NULL,
- deadline, NULL);
+ grpc_slice_from_static_string("/foo"), NULL, deadline, NULL);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@@ -231,16 +223,15 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), (void *)1, NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
- dispatch_async(
- dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- int s = accept(sl, NULL, NULL);
- GPR_ASSERT(s >= 0);
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ int s = accept(sl, NULL, NULL);
+ GPR_ASSERT(s >= 0);
- // Close the connection after 1 second to trigger Cronet's on_failed()
- sleep(1);
- close(s);
- close(sl);
- });
+ // Close the connection after 1 second to trigger Cronet's on_failed()
+ sleep(1);
+ close(s);
+ close(sl);
+ });
CQ_EXPECT_COMPLETION(cqv, (void *)1, 1);
cq_verify(cqv);
@@ -275,10 +266,8 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
args = add_disable_client_authority_filter_args(args);
grpc_call *c;
- grpc_slice request_payload_slice =
- grpc_slice_from_copied_string("hello world");
- grpc_byte_buffer *request_payload =
- grpc_raw_byte_buffer_create(&request_payload_slice, 1);
+ grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5);
grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"),
grpc_slice_from_static_string("val1"),
@@ -294,8 +283,7 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
gpr_join_host_port(&addr, "127.0.0.1", port);
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
stream_engine *cronetEngine = [Cronet getGlobalEngine];
- grpc_channel *client =
- grpc_cronet_secure_channel_create(cronetEngine, addr, args, NULL);
+ grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, args, NULL);
cq_verifier *cqv = cq_verifier_create(cq);
grpc_op ops[6];
@@ -310,8 +298,7 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
grpc_slice details;
c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
- grpc_slice_from_static_string("/foo"), NULL,
- deadline, NULL);
+ grpc_slice_from_static_string("/foo"), NULL, deadline, NULL);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
@@ -319,8 +306,7 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
- __weak XCTestExpectation *expectation =
- [self expectationWithDescription:@"Coalescing"];
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Coalescing"];
int sl = socket(AF_INET, SOCK_STREAM, 0);
GPR_ASSERT(sl >= 0);
@@ -332,61 +318,60 @@ grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *a
GPR_ASSERT(0 == bind(sl, (struct sockaddr *)&s_addr, sizeof(s_addr)));
GPR_ASSERT(0 == listen(sl, 5));
- dispatch_async(
- dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- int s = accept(sl, NULL, NULL);
- GPR_ASSERT(s >= 0);
- struct timeval tv;
- tv.tv_sec = 2;
- tv.tv_usec = 0;
- setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
-
- // Make an TLS endpoint to receive Cronet's transmission
- SSL_CTX *ctx = SSL_CTX_new(TLSv1_2_server_method());
- init_ctx(ctx);
- SSL *ssl = SSL_new(ctx);
- SSL_set_fd(ssl, s);
- SSL_accept(ssl);
-
- const char magic[] = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
-
- char buf[4096];
- long len;
- BOOL coalesced = NO;
- while ((len = SSL_read(ssl, buf, sizeof(buf))) > 0) {
- gpr_log(GPR_DEBUG, "Read len: %ld", len);
-
- // Analyze the HTTP/2 frames in the same TLS PDU to identify if
- // coalescing is successful
- unsigned int p = 0;
- while (p < len) {
- if (len - p >= 24 && 0 == memcmp(&buf[p], magic, 24)) {
- p += 24;
- continue;
- }
-
- if (buf[p + 3] == 0 && // Type is DATA
- parse_h2_length(&buf[p]) == 0x10 && // Length is correct
- (buf[p + 4] & 1) != 0 && // EOS bit is set
- 0 == memcmp("hello world", &buf[p + 14],
- 11)) { // Message is correct
- coalesced = YES;
- break;
- }
- p += (parse_h2_length(&buf[p]) + 9);
- }
- if (coalesced) {
- break;
- }
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ int s = accept(sl, NULL, NULL);
+ GPR_ASSERT(s >= 0);
+ struct timeval tv;
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+ setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+
+ // Make an TLS endpoint to receive Cronet's transmission
+ SSL_CTX *ctx = SSL_CTX_new(TLSv1_2_server_method());
+ init_ctx(ctx);
+ SSL *ssl = SSL_new(ctx);
+ SSL_set_fd(ssl, s);
+ SSL_accept(ssl);
+
+ const char magic[] = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
+
+ char buf[4096];
+ long len;
+ BOOL coalesced = NO;
+ while ((len = SSL_read(ssl, buf, sizeof(buf))) > 0) {
+ gpr_log(GPR_DEBUG, "Read len: %ld", len);
+
+ // Analyze the HTTP/2 frames in the same TLS PDU to identify if
+ // coalescing is successful
+ unsigned int p = 0;
+ while (p < len) {
+ if (len - p >= 24 && 0 == memcmp(&buf[p], magic, 24)) {
+ p += 24;
+ continue;
}
- XCTAssert(coalesced == useCoalescing);
- SSL_free(ssl);
- SSL_CTX_free(ctx);
- close(s);
- close(sl);
- [expectation fulfill];
- });
+ if (buf[p + 3] == 0 && // Type is DATA
+ parse_h2_length(&buf[p]) == 0x10 && // Length is correct
+ (buf[p + 4] & 1) != 0 && // EOS bit is set
+ 0 == memcmp("hello world", &buf[p + 14],
+ 11)) { // Message is correct
+ coalesced = YES;
+ break;
+ }
+ p += (parse_h2_length(&buf[p]) + 9);
+ }
+ if (coalesced) {
+ break;
+ }
+ }
+
+ XCTAssert(coalesced == useCoalescing);
+ SSL_free(ssl);
+ SSL_CTX_free(ctx);
+ close(s);
+ close(sl);
+ [expectation fulfill];
+ });
memset(ops, 0, sizeof(ops));
op = ops;
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index e716198009..5cd0231db7 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -20,16 +20,16 @@
#import <XCTest/XCTest.h>
#import <grpc/grpc.h>
-#import <GRPCClient/GRPCCall.h>
#import <GRPCClient/GRPCCall+ChannelArg.h>
#import <GRPCClient/GRPCCall+OAuth2.h>
#import <GRPCClient/GRPCCall+Tests.h>
+#import <GRPCClient/GRPCCall.h>
#import <GRPCClient/internal_testing/GRPCCall+InternalTests.h>
#import <ProtoRPC/ProtoMethod.h>
#import <RemoteTest/Messages.pbobjc.h>
+#import <RxLibrary/GRXBufferedPipe.h>
#import <RxLibrary/GRXWriteable.h>
#import <RxLibrary/GRXWriter+Immediate.h>
-#import <RxLibrary/GRXBufferedPipe.h>
#include <netinet/in.h>
@@ -37,10 +37,10 @@
#define TEST_TIMEOUT 16
-static NSString * const kHostAddress = @"localhost:5050";
-static NSString * const kPackage = @"grpc.testing";
-static NSString * const kService = @"TestService";
-static NSString * const kRemoteSSLHost = @"grpc-test.sandbox.googleapis.com";
+static NSString *const kHostAddress = @"localhost:5050";
+static NSString *const kPackage = @"grpc.testing";
+static NSString *const kService = @"TestService";
+static NSString *const kRemoteSSLHost = @"grpc-test.sandbox.googleapis.com";
static GRPCProtoMethod *kInexistentMethod;
static GRPCProtoMethod *kEmptyCallMethod;
@@ -49,15 +49,17 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
/** Observer class for testing that responseMetadata is KVO-compliant */
@interface PassthroughObserver : NSObject
-- (instancetype) initWithCallback:(void (^)(NSString*, id, NSDictionary*))callback
+- (instancetype)initWithCallback:(void (^)(NSString *, id, NSDictionary *))callback
NS_DESIGNATED_INITIALIZER;
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change
+- (void)observeValueForKeyPath:(NSString *)keyPath
+ ofObject:(id)object
+ change:(NSDictionary *)change
context:(void *)context;
@end
@implementation PassthroughObserver {
- void (^_callback)(NSString*, id, NSDictionary*);
+ void (^_callback)(NSString *, id, NSDictionary *);
}
- (instancetype)init {
@@ -84,7 +86,7 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
@end
-# pragma mark Tests
+#pragma mark Tests
/**
* A few tests similar to InteropTests, but which use the generic gRPC client (GRPCCall) rather than
@@ -108,18 +110,14 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
[GRPCCall useInsecureConnectionsForHost:kHostAddress];
// This method isn't implemented by the remote server.
- kInexistentMethod = [[GRPCProtoMethod alloc] initWithPackage:kPackage
- service:kService
- method:@"Inexistent"];
- kEmptyCallMethod = [[GRPCProtoMethod alloc] initWithPackage:kPackage
- service:kService
- method:@"EmptyCall"];
- kUnaryCallMethod = [[GRPCProtoMethod alloc] initWithPackage:kPackage
- service:kService
- method:@"UnaryCall"];
- kFullDuplexCallMethod = [[GRPCProtoMethod alloc] initWithPackage:kPackage
- service:kService
- method:@"FullDuplexCall"];
+ kInexistentMethod =
+ [[GRPCProtoMethod alloc] initWithPackage:kPackage service:kService method:@"Inexistent"];
+ kEmptyCallMethod =
+ [[GRPCProtoMethod alloc] initWithPackage:kPackage service:kService method:@"EmptyCall"];
+ kUnaryCallMethod =
+ [[GRPCProtoMethod alloc] initWithPackage:kPackage service:kService method:@"UnaryCall"];
+ kFullDuplexCallMethod =
+ [[GRPCProtoMethod alloc] initWithPackage:kPackage service:kService method:@"FullDuplexCall"];
}
- (void)testConnectionToRemoteServer {
@@ -129,13 +127,15 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
path:kInexistentMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTFail(@"Received unexpected response: %@", value);
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNotNil(errorOrNil, @"Finished without error!");
- XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil);
- [expectation fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTFail(@"Received unexpected response: %@", value);
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNotNil(errorOrNil, @"Finished without error!");
+ XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil);
+ [expectation fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
@@ -143,21 +143,24 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
}
- (void)testEmptyRPC {
- __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
+ __weak XCTestExpectation *response =
+ [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
path:kEmptyCallMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssertNotNil(value, @"nil value received as response.");
- XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
- [response fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
- [completion fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
+ [response fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ [completion fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
@@ -178,18 +181,20 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
path:kUnaryCallMethod.HTTPPath
requestsWriter:requestsWriter];
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssertNotNil(value, @"nil value received as response.");
- XCTAssertGreaterThan(value.length, 0, @"Empty response received.");
- RMTSimpleResponse *responseProto = [RMTSimpleResponse parseFromData:value error:NULL];
- // We expect empty strings, not nil:
- XCTAssertNotNil(responseProto.username, @"Response's username is nil.");
- XCTAssertNotNil(responseProto.oauthScope, @"Response's OAuth scope is nil.");
- [response fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
- [completion fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertGreaterThan(value.length, 0, @"Empty response received.");
+ RMTSimpleResponse *responseProto = [RMTSimpleResponse parseFromData:value error:NULL];
+ // We expect empty strings, not nil:
+ XCTAssertNotNil(responseProto.username, @"Response's username is nil.");
+ XCTAssertNotNil(responseProto.oauthScope, @"Response's OAuth scope is nil.");
+ [response fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ [completion fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
@@ -210,20 +215,22 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
call.oauth2AccessToken = @"bogusToken";
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTFail(@"Received unexpected response: %@", value);
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNotNil(errorOrNil, @"Finished without error!");
- XCTAssertEqual(errorOrNil.code, 16, @"Finished with unexpected error: %@", errorOrNil);
- XCTAssertEqualObjects(call.responseHeaders, errorOrNil.userInfo[kGRPCHeadersKey],
- @"Headers in the NSError object and call object differ.");
- XCTAssertEqualObjects(call.responseTrailers, errorOrNil.userInfo[kGRPCTrailersKey],
- @"Trailers in the NSError object and call object differ.");
- NSString *challengeHeader = call.oauth2ChallengeHeader;
- XCTAssertGreaterThan(challengeHeader.length, 0,
- @"No challenge in response headers %@", call.responseHeaders);
- [expectation fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTFail(@"Received unexpected response: %@", value);
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNotNil(errorOrNil, @"Finished without error!");
+ XCTAssertEqual(errorOrNil.code, 16, @"Finished with unexpected error: %@", errorOrNil);
+ XCTAssertEqualObjects(call.responseHeaders, errorOrNil.userInfo[kGRPCHeadersKey],
+ @"Headers in the NSError object and call object differ.");
+ XCTAssertEqualObjects(call.responseTrailers, errorOrNil.userInfo[kGRPCTrailersKey],
+ @"Trailers in the NSError object and call object differ.");
+ NSString *challengeHeader = call.oauth2ChallengeHeader;
+ XCTAssertGreaterThan(challengeHeader.length, 0, @"No challenge in response headers %@",
+ call.responseHeaders);
+ [expectation fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
@@ -231,38 +238,43 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
}
- (void)testResponseMetadataKVO {
- __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
+ __weak XCTestExpectation *response =
+ [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
__weak XCTestExpectation *metadata = [self expectationWithDescription:@"Metadata changed."];
-
+
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
path:kEmptyCallMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
-
- PassthroughObserver *observer = [[PassthroughObserver alloc] initWithCallback:^(NSString *keypath, id object, NSDictionary * change) {
- if ([keypath isEqual: @"responseHeaders"]) {
- [metadata fulfill];
- }
- }];
-
+
+ PassthroughObserver *observer = [[PassthroughObserver alloc]
+ initWithCallback:^(NSString *keypath, id object, NSDictionary *change) {
+ if ([keypath isEqual:@"responseHeaders"]) {
+ [metadata fulfill];
+ }
+ }];
+
[call addObserver:observer forKeyPath:@"responseHeaders" options:0 context:NULL];
-
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssertNotNil(value, @"nil value received as response.");
- XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
- [response fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
- [completion fulfill];
- }];
-
+
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
+ [response fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ [completion fulfill];
+ }];
+
[call startWithWriteable:responsesWriteable];
-
+
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
- (void)testUserAgentPrefix {
- __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
+ __weak XCTestExpectation *response =
+ [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
@@ -272,46 +284,45 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
// user-agent value, which we confirm.
call.requestHeaders[@"x-grpc-test-echo-useragent"] = @"";
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssertNotNil(value, @"nil value received as response.");
- XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
-
- NSString *userAgent = call.responseHeaders[@"x-grpc-test-echo-useragent"];
- NSError *error = nil;
-
- // Test the regex is correct
- NSString *expectedUserAgent = @"Foo grpc-objc/";
- expectedUserAgent =
- [expectedUserAgent stringByAppendingString:GRPC_OBJC_VERSION_STRING];
- expectedUserAgent =
- [expectedUserAgent stringByAppendingString:@" grpc-c/"];
- expectedUserAgent =
- [expectedUserAgent stringByAppendingString:GRPC_C_VERSION_STRING];
- expectedUserAgent =
- [expectedUserAgent stringByAppendingString:@" (ios; chttp2; "];
- expectedUserAgent =
- [expectedUserAgent stringByAppendingString:[NSString stringWithUTF8String:grpc_g_stands_for()]];
- expectedUserAgent = [expectedUserAgent stringByAppendingString:@")"];
- XCTAssertEqualObjects(userAgent, expectedUserAgent);
-
- // Change in format of user-agent field in a direction that does not match the regex will likely
- // cause problem for certain gRPC users. For details, refer to internal doc https://goo.gl/c2diBc
- NSRegularExpression *regex =
- [NSRegularExpression regularExpressionWithPattern:@" grpc-[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?/[^ ,]+( \\([^)]*\\))?"
- options:0
- error:&error];
- NSString *customUserAgent =
- [regex stringByReplacingMatchesInString:userAgent
- options:0
- range:NSMakeRange(0, [userAgent length])
- withTemplate:@""];
- XCTAssertEqualObjects(customUserAgent, @"Foo");
-
- [response fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
- [completion fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
+
+ NSString *userAgent = call.responseHeaders[@"x-grpc-test-echo-useragent"];
+ NSError *error = nil;
+
+ // Test the regex is correct
+ NSString *expectedUserAgent = @"Foo grpc-objc/";
+ expectedUserAgent = [expectedUserAgent stringByAppendingString:GRPC_OBJC_VERSION_STRING];
+ expectedUserAgent = [expectedUserAgent stringByAppendingString:@" grpc-c/"];
+ expectedUserAgent = [expectedUserAgent stringByAppendingString:GRPC_C_VERSION_STRING];
+ expectedUserAgent = [expectedUserAgent stringByAppendingString:@" (ios; chttp2; "];
+ expectedUserAgent = [expectedUserAgent
+ stringByAppendingString:[NSString stringWithUTF8String:grpc_g_stands_for()]];
+ expectedUserAgent = [expectedUserAgent stringByAppendingString:@")"];
+ XCTAssertEqualObjects(userAgent, expectedUserAgent);
+
+ // Change in format of user-agent field in a direction that does not match the regex will
+ // likely cause problem for certain gRPC users. For details, refer to internal doc
+ // https://goo.gl/c2diBc
+ NSRegularExpression *regex = [NSRegularExpression
+ regularExpressionWithPattern:@" grpc-[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?/[^ ,]+( \\([^)]*\\))?"
+ options:0
+ error:&error];
+ NSString *customUserAgent =
+ [regex stringByReplacingMatchesInString:userAgent
+ options:0
+ range:NSMakeRange(0, [userAgent length])
+ withTemplate:@""];
+ XCTAssertEqualObjects(customUserAgent, @"Foo");
+
+ [response fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ [completion fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
@@ -319,7 +330,8 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
}
- (void)testTrailers {
- __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
+ __weak XCTestExpectation *response =
+ [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
@@ -327,21 +339,22 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
// Setting this special key in the header will cause the interop server to echo back the
// trailer data.
- const unsigned char raw_bytes[] = {1,2,3,4};
+ const unsigned char raw_bytes[] = {1, 2, 3, 4};
NSData *trailer_data = [NSData dataWithBytes:raw_bytes length:sizeof(raw_bytes)];
call.requestHeaders[@"x-grpc-test-echo-trailing-bin"] = trailer_data;
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssertNotNil(value, @"nil value received as response.");
- XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
- [response fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
- XCTAssertEqualObjects((NSData *)call.responseTrailers[@"x-grpc-test-echo-trailing-bin"],
- trailer_data,
- @"Did not receive expected trailer");
- [completion fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value);
+ [response fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ XCTAssertEqualObjects((NSData *)call.responseTrailers[@"x-grpc-test-echo-trailing-bin"],
+ trailer_data, @"Did not receive expected trailer");
+ [completion fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
@@ -351,15 +364,12 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
- (void)testExceptions {
// Try to set parameters to nil for GRPCCall. This should cause an exception
@try {
- (void)[[GRPCCall alloc] initWithHost:nil
- path:nil
- requestsWriter:nil];
+ (void)[[GRPCCall alloc] initWithHost:nil path:nil requestsWriter:nil];
XCTFail(@"Did not receive an exception when parameters are nil");
- } @catch(NSException *theException) {
+ } @catch (NSException *theException) {
NSLog(@"Received exception as expected: %@", theException.name);
}
-
// Set state to Finished by force
GRXWriter *requestsWriter = [GRXWriter emptyWriter];
[requestsWriter finishWithError:nil];
@@ -368,10 +378,9 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
path:kUnaryCallMethod.HTTPPath
requestsWriter:requestsWriter];
XCTFail(@"Did not receive an exception when GRXWriter has incorrect state.");
- } @catch(NSException *theException) {
+ } @catch (NSException *theException) {
NSLog(@"Received exception as expected: %@", theException.name);
}
-
}
- (void)testIdempotentProtoRPC {
@@ -387,20 +396,24 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
path:kUnaryCallMethod.HTTPPath
requestsWriter:requestsWriter];
- [GRPCCall setCallSafety:GRPCCallSafetyIdempotentRequest host:kHostAddress path:kUnaryCallMethod.HTTPPath];
-
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssertNotNil(value, @"nil value received as response.");
- XCTAssertGreaterThan(value.length, 0, @"Empty response received.");
- RMTSimpleResponse *responseProto = [RMTSimpleResponse parseFromData:value error:NULL];
- // We expect empty strings, not nil:
- XCTAssertNotNil(responseProto.username, @"Response's username is nil.");
- XCTAssertNotNil(responseProto.oauthScope, @"Response's OAuth scope is nil.");
- [response fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
- [completion fulfill];
- }];
+ [GRPCCall setCallSafety:GRPCCallSafetyIdempotentRequest
+ host:kHostAddress
+ path:kUnaryCallMethod.HTTPPath];
+
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssertNotNil(value, @"nil value received as response.");
+ XCTAssertGreaterThan(value.length, 0, @"Empty response received.");
+ RMTSimpleResponse *responseProto = [RMTSimpleResponse parseFromData:value error:NULL];
+ // We expect empty strings, not nil:
+ XCTAssertNotNil(responseProto.username, @"Response's username is nil.");
+ XCTAssertNotNil(responseProto.oauthScope, @"Response's OAuth scope is nil.");
+ [response fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
+ [completion fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
@@ -412,10 +425,12 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
RMTSimpleRequest *request = [RMTSimpleRequest message];
request.responseSize = kPayloadSize;
- __weak XCTestExpectation *expectation1 = [self expectationWithDescription:@"AlternateDispatchQueue1"];
+ __weak XCTestExpectation *expectation1 =
+ [self expectationWithDescription:@"AlternateDispatchQueue1"];
// Use default (main) dispatch queue
- NSString *main_queue_label = [NSString stringWithUTF8String:dispatch_queue_get_label(dispatch_get_main_queue())];
+ NSString *main_queue_label =
+ [NSString stringWithUTF8String:dispatch_queue_get_label(dispatch_get_main_queue())];
GRXWriter *requestsWriter1 = [GRXWriter writerWithValue:[request data]];
@@ -423,20 +438,24 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
path:kUnaryCallMethod.HTTPPath
requestsWriter:requestsWriter1];
- id<GRXWriteable> responsesWriteable1 = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)];
- XCTAssert([label isEqualToString:main_queue_label]);
+ id<GRXWriteable> responsesWriteable1 =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ NSString *label =
+ [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)];
+ XCTAssert([label isEqualToString:main_queue_label]);
- [expectation1 fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- }];
+ [expectation1 fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil){
+ }];
[call1 startWithWriteable:responsesWriteable1];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
// Use a custom queue
- __weak XCTestExpectation *expectation2 = [self expectationWithDescription:@"AlternateDispatchQueue2"];
+ __weak XCTestExpectation *expectation2 =
+ [self expectationWithDescription:@"AlternateDispatchQueue2"];
NSString *queue_label = @"test.queue1";
dispatch_queue_t queue = dispatch_queue_create([queue_label UTF8String], DISPATCH_QUEUE_SERIAL);
@@ -449,13 +468,16 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
[call2 setResponseDispatchQueue:queue];
- id<GRXWriteable> responsesWriteable2 = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)];
- XCTAssert([label isEqualToString:queue_label]);
+ id<GRXWriteable> responsesWriteable2 =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ NSString *label =
+ [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)];
+ XCTAssert([label isEqualToString:queue_label]);
- [expectation2 fulfill];
- } completionHandler:^(NSError *errorOrNil) {
- }];
+ [expectation2 fulfill];
+ }
+ completionHandler:^(NSError *errorOrNil){
+ }];
[call2 startWithWriteable:responsesWriteable2];
@@ -470,13 +492,16 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
path:kFullDuplexCallMethod.HTTPPath
requestsWriter:pipe];
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTAssert(0, @"Failure: response received; Expect: no response received.");
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNotNil(errorOrNil, @"Failure: no error received; Expect: receive deadline exceeded.");
- XCTAssertEqual(errorOrNil.code, GRPCErrorCodeDeadlineExceeded);
- [completion fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTAssert(0, @"Failure: response received; Expect: no response received.");
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNotNil(errorOrNil,
+ @"Failure: no error received; Expect: receive deadline exceeded.");
+ XCTAssertEqual(errorOrNil.code, GRPCErrorCodeDeadlineExceeded);
+ [completion fulfill];
+ }];
call.timeout = 0.001;
[call startWithWriteable:responsesWriteable];
@@ -490,8 +515,8 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
int fd = socket(AF_INET, SOCK_STREAM, 0);
- XCTAssertEqual(bind(fd, (struct sockaddr*)&addr, sizeof(addr)), 0);
- XCTAssertEqual(getsockname(fd, (struct sockaddr*)&addr, &addr_len), 0);
+ XCTAssertEqual(bind(fd, (struct sockaddr *)&addr, sizeof(addr)), 0);
+ XCTAssertEqual(getsockname(fd, (struct sockaddr *)&addr, &addr_len), 0);
XCTAssertEqual(addr_len, sizeof(addr));
close(fd);
return addr.sin_port;
@@ -499,21 +524,23 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
- (void)testErrorCode {
int port = [self findFreePort];
- NSString * const kDummyAddress = [NSString stringWithFormat:@"localhost:%d", port];
+ NSString *const kDummyAddress = [NSString stringWithFormat:@"localhost:%d", port];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kDummyAddress
path:kEmptyCallMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- // Should not reach here
- XCTAssert(NO);
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNotNil(errorOrNil, @"Finished with no error");
- XCTAssertEqual(errorOrNil.code, GRPC_STATUS_UNAVAILABLE);
- [completion fulfill];
- }];
+ id<GRXWriteable> responsesWriteable =
+ [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ // Should not reach here
+ XCTAssert(NO);
+ }
+ completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNotNil(errorOrNil, @"Finished with no error");
+ XCTAssertEqual(errorOrNil.code, GRPC_STATUS_UNAVAILABLE);
+ [completion fulfill];
+ }];
[call startWithWriteable:responsesWriteable];
diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m
index bfc4755c15..1e1da2dd66 100644
--- a/src/objective-c/tests/InteropTests.m
+++ b/src/objective-c/tests/InteropTests.m
@@ -22,17 +22,17 @@
#import <Cronet/Cronet.h>
#import <GRPCClient/GRPCCall+ChannelArg.h>
+#import <GRPCClient/GRPCCall+Cronet.h>
#import <GRPCClient/GRPCCall+Tests.h>
#import <GRPCClient/internal_testing/GRPCCall+InternalTests.h>
-#import <GRPCClient/GRPCCall+Cronet.h>
#import <ProtoRPC/ProtoRPC.h>
#import <RemoteTest/Messages.pbobjc.h>
#import <RemoteTest/Test.pbobjc.h>
#import <RemoteTest/Test.pbrpc.h>
#import <RxLibrary/GRXBufferedPipe.h>
#import <RxLibrary/GRXWriter+Immediate.h>
-#import <grpc/support/log.h>
#import <grpc/grpc.h>
+#import <grpc/support/log.h>
#define TEST_TIMEOUT 32
@@ -61,7 +61,7 @@
@implementation RMTStreamingOutputCallResponse (Constructors)
+ (instancetype)messageWithPayloadSize:(NSNumber *)payloadSize {
- RMTStreamingOutputCallResponse * response = [self message];
+ RMTStreamingOutputCallResponse *response = [self message];
response.payload.type = RMTPayloadType_Compressable;
response.payload.body = [NSMutableData dataWithLength:payloadSize.unsignedIntegerValue];
return response;
@@ -113,14 +113,15 @@ BOOL isRemoteInteropTest(NSString *host) {
GPBEmpty *request = [GPBEmpty message];
- [_service emptyCallWithRequest:request handler:^(GPBEmpty *response, NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ [_service emptyCallWithRequest:request
+ handler:^(GPBEmpty *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- id expectedResponse = [GPBEmpty message];
- XCTAssertEqualObjects(response, expectedResponse);
+ id expectedResponse = [GPBEmpty message];
+ XCTAssertEqualObjects(response, expectedResponse);
- [expectation fulfill];
- }];
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -134,16 +135,17 @@ BOOL isRemoteInteropTest(NSString *host) {
request.responseSize = 314159;
request.payload.body = [NSMutableData dataWithLength:271828];
- [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ [_service unaryCallWithRequest:request
+ handler:^(RMTSimpleResponse *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
- expectedResponse.payload.type = RMTPayloadType_Compressable;
- expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
- XCTAssertEqualObjects(response, expectedResponse);
+ RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
+ expectedResponse.payload.type = RMTPayloadType_Compressable;
+ expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
+ XCTAssertEqualObjects(response, expectedResponse);
- [expectation fulfill];
- }];
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -158,29 +160,30 @@ BOOL isRemoteInteropTest(NSString *host) {
request.payload.body = [NSMutableData dataWithLength:10];
[GRPCCall enableOpBatchLog:YES];
- [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
-
- RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
- expectedResponse.payload.type = RMTPayloadType_Compressable;
- expectedResponse.payload.body = [NSMutableData dataWithLength:10];
- XCTAssertEqualObjects(response, expectedResponse);
-
- // The test is a success if there is a batch of exactly 3 ops (SEND_INITIAL_METADATA,
- // SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT). Without packet coalescing each batch of ops contains
- // only one op.
- NSArray *opBatches = [GRPCCall obtainAndCleanOpBatchLog];
- const NSInteger kExpectedOpBatchSize = 3;
- for (NSObject *o in opBatches) {
- if ([o isKindOfClass:[NSArray class]]) {
- NSArray *batch = (NSArray *)o;
- if ([batch count] == kExpectedOpBatchSize) {
- [expectation fulfill];
- break;
- }
- }
- }
- }];
+ [_service unaryCallWithRequest:request
+ handler:^(RMTSimpleResponse *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+
+ RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
+ expectedResponse.payload.type = RMTPayloadType_Compressable;
+ expectedResponse.payload.body = [NSMutableData dataWithLength:10];
+ XCTAssertEqualObjects(response, expectedResponse);
+
+ // The test is a success if there is a batch of exactly 3 ops
+ // (SEND_INITIAL_METADATA, SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT). Without
+ // packet coalescing each batch of ops contains only one op.
+ NSArray *opBatches = [GRPCCall obtainAndCleanOpBatchLog];
+ const NSInteger kExpectedOpBatchSize = 3;
+ for (NSObject *o in opBatches) {
+ if ([o isKindOfClass:[NSArray class]]) {
+ NSArray *batch = (NSArray *)o;
+ if ([batch count] == kExpectedOpBatchSize) {
+ [expectation fulfill];
+ break;
+ }
+ }
+ }
+ }];
[self waitForExpectationsWithTimeout:16 handler:nil];
[GRPCCall enableOpBatchLog:NO];
@@ -191,14 +194,15 @@ BOOL isRemoteInteropTest(NSString *host) {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"];
RMTSimpleRequest *request = [RMTSimpleRequest message];
- const int32_t kPayloadSize = 4 * 1024 * 1024 - self.encodingOverhead; // 4MB - encoding overhead
+ const int32_t kPayloadSize = 4 * 1024 * 1024 - self.encodingOverhead; // 4MB - encoding overhead
request.responseSize = kPayloadSize;
- [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssertEqual(response.payload.body.length, kPayloadSize);
- [expectation fulfill];
- }];
+ [_service unaryCallWithRequest:request
+ handler:^(RMTSimpleResponse *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertEqual(response.payload.body.length, kPayloadSize);
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -208,18 +212,23 @@ BOOL isRemoteInteropTest(NSString *host) {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ResponseOverMaxSize"];
RMTSimpleRequest *request = [RMTSimpleRequest message];
- const int32_t kPayloadSize = 4 * 1024 * 1024 - self.encodingOverhead + 1; // 1B over max size
+ const int32_t kPayloadSize = 4 * 1024 * 1024 - self.encodingOverhead + 1; // 1B over max size
request.responseSize = kPayloadSize;
- [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
- // TODO(jcanizales): Catch the error and rethrow it with an actionable message:
- // - Use +[GRPCCall setResponseSizeLimit:forHost:] to set a higher limit.
- // - If you're developing the server, consider using response streaming, or let clients filter
- // responses by setting a google.protobuf.FieldMask in the request:
- // https://github.com/google/protobuf/blob/master/src/google/protobuf/field_mask.proto
- XCTAssertEqualObjects(error.localizedDescription, @"Received message larger than max (4194305 vs. 4194304)");
- [expectation fulfill];
- }];
+ [_service unaryCallWithRequest:request
+ handler:^(RMTSimpleResponse *response, NSError *error) {
+ // TODO(jcanizales): Catch the error and rethrow it with an actionable
+ // message:
+ // - Use +[GRPCCall setResponseSizeLimit:forHost:] to set a higher limit.
+ // - If you're developing the server, consider using response streaming,
+ // or let clients filter
+ // responses by setting a google.protobuf.FieldMask in the request:
+ // https://github.com/google/protobuf/blob/master/src/google/protobuf/field_mask.proto
+ XCTAssertEqualObjects(
+ error.localizedDescription,
+ @"Received message larger than max (4194305 vs. 4194304)");
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -230,16 +239,17 @@ BOOL isRemoteInteropTest(NSString *host) {
[self expectationWithDescription:@"HigherResponseSizeLimit"];
RMTSimpleRequest *request = [RMTSimpleRequest message];
- const size_t kPayloadSize = 5 * 1024 * 1024; // 5MB
+ const size_t kPayloadSize = 5 * 1024 * 1024; // 5MB
request.responseSize = kPayloadSize;
[GRPCCall setResponseSizeLimit:6 * 1024 * 1024 forHost:self.class.host];
- [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssertEqual(response.payload.body.length, kPayloadSize);
- [expectation fulfill];
- }];
+ [_service unaryCallWithRequest:request
+ handler:^(RMTSimpleResponse *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertEqual(response.payload.body.length, kPayloadSize);
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -260,19 +270,21 @@ BOOL isRemoteInteropTest(NSString *host) {
RMTStreamingInputCallRequest *request4 = [RMTStreamingInputCallRequest message];
request4.payload.body = [NSMutableData dataWithLength:45904];
- GRXWriter *writer = [GRXWriter writerWithContainer:@[request1, request2, request3, request4]];
+ GRXWriter *writer = [GRXWriter writerWithContainer:@[ request1, request2, request3, request4 ]];
[_service streamingInputCallWithRequestsWriter:writer
handler:^(RMTStreamingInputCallResponse *response,
NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertNil(
+ error, @"Finished with unexpected error: %@", error);
- RMTStreamingInputCallResponse *expectedResponse = [RMTStreamingInputCallResponse message];
- expectedResponse.aggregatedPayloadSize = 74922;
- XCTAssertEqualObjects(response, expectedResponse);
+ RMTStreamingInputCallResponse *expectedResponse =
+ [RMTStreamingInputCallResponse message];
+ expectedResponse.aggregatedPayloadSize = 74922;
+ XCTAssertEqualObjects(response, expectedResponse);
- [expectation fulfill];
- }];
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -281,7 +293,7 @@ BOOL isRemoteInteropTest(NSString *host) {
XCTAssertNotNil(self.class.host);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"];
- NSArray *expectedSizes = @[@31415, @9, @2653, @58979];
+ NSArray *expectedSizes = @[ @31415, @9, @2653, @58979 ];
RMTStreamingOutputCallRequest *request = [RMTStreamingOutputCallRequest message];
for (NSNumber *size in expectedSizes) {
@@ -291,25 +303,27 @@ BOOL isRemoteInteropTest(NSString *host) {
}
__block int index = 0;
- [_service streamingOutputCallWithRequest:request
- eventHandler:^(BOOL done,
- RMTStreamingOutputCallResponse *response,
- NSError *error){
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssertTrue(done || response, @"Event handler called without an event.");
-
- if (response) {
- XCTAssertLessThan(index, 4, @"More than 4 responses received.");
- id expected = [RMTStreamingOutputCallResponse messageWithPayloadSize:expectedSizes[index]];
- XCTAssertEqualObjects(response, expected);
- index += 1;
- }
-
- if (done) {
- XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index);
- [expectation fulfill];
- }
- }];
+ [_service
+ streamingOutputCallWithRequest:request
+ eventHandler:^(BOOL done, RMTStreamingOutputCallResponse *response,
+ NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertTrue(done || response,
+ @"Event handler called without an event.");
+
+ if (response) {
+ XCTAssertLessThan(index, 4, @"More than 4 responses received.");
+ id expected = [RMTStreamingOutputCallResponse
+ messageWithPayloadSize:expectedSizes[index]];
+ XCTAssertEqualObjects(response, expected);
+ index += 1;
+ }
+
+ if (done) {
+ XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index);
+ [expectation fulfill];
+ }
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -318,8 +332,8 @@ BOOL isRemoteInteropTest(NSString *host) {
XCTAssertNotNil(self.class.host);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPong"];
- NSArray *requests = @[@27182, @8, @1828, @45904];
- NSArray *responses = @[@31415, @9, @2653, @58979];
+ NSArray *requests = @[ @27182, @8, @1828, @45904 ];
+ NSArray *responses = @[ @31415, @9, @2653, @58979 ];
GRXBufferedPipe *requestsBuffer = [[GRXBufferedPipe alloc] init];
@@ -330,31 +344,34 @@ BOOL isRemoteInteropTest(NSString *host) {
[requestsBuffer writeValue:request];
[_service fullDuplexCallWithRequestsWriter:requestsBuffer
- eventHandler:^(BOOL done,
- RMTStreamingOutputCallResponse *response,
+ eventHandler:^(BOOL done, RMTStreamingOutputCallResponse *response,
NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssertTrue(done || response, @"Event handler called without an event.");
-
- if (response) {
- XCTAssertLessThan(index, 4, @"More than 4 responses received.");
- id expected = [RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]];
- XCTAssertEqualObjects(response, expected);
- index += 1;
- if (index < 4) {
- id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index]
- requestedResponseSize:responses[index]];
- [requestsBuffer writeValue:request];
- } else {
- [requestsBuffer writesFinishedWithError:nil];
- }
- }
-
- if (done) {
- XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index);
- [expectation fulfill];
- }
- }];
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertTrue(done || response,
+ @"Event handler called without an event.");
+
+ if (response) {
+ XCTAssertLessThan(index, 4, @"More than 4 responses received.");
+ id expected = [RMTStreamingOutputCallResponse
+ messageWithPayloadSize:responses[index]];
+ XCTAssertEqualObjects(response, expected);
+ index += 1;
+ if (index < 4) {
+ id request = [RMTStreamingOutputCallRequest
+ messageWithPayloadSize:requests[index]
+ requestedResponseSize:responses[index]];
+ [requestsBuffer writeValue:request];
+ } else {
+ [requestsBuffer writesFinishedWithError:nil];
+ }
+ }
+
+ if (done) {
+ XCTAssertEqual(index, 4, @"Received %i responses instead of 4.",
+ index);
+ [expectation fulfill];
+ }
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -362,13 +379,12 @@ BOOL isRemoteInteropTest(NSString *host) {
XCTAssertNotNil(self.class.host);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"];
[_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter]
- eventHandler:^(BOOL done,
- RMTStreamingOutputCallResponse *response,
+ eventHandler:^(BOOL done, RMTStreamingOutputCallResponse *response,
NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssert(done, @"Unexpected response: %@", response);
- [expectation fulfill];
- }];
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssert(done, @"Unexpected response: %@", response);
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -379,13 +395,13 @@ BOOL isRemoteInteropTest(NSString *host) {
// A buffered pipe to which we never write any value acts as a writer that just hangs.
GRXBufferedPipe *requestsBuffer = [[GRXBufferedPipe alloc] init];
- GRPCProtoCall *call =
- [_service RPCToStreamingInputCallWithRequestsWriter:requestsBuffer
- handler:^(RMTStreamingInputCallResponse *response,
- NSError *error) {
- XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
- [expectation fulfill];
- }];
+ GRPCProtoCall *call = [_service
+ RPCToStreamingInputCallWithRequestsWriter:requestsBuffer
+ handler:^(RMTStreamingInputCallResponse *response,
+ NSError *error) {
+ XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
+ [expectation fulfill];
+ }];
XCTAssertEqual(call.state, GRXWriterStateNotStarted);
[call start];
@@ -399,35 +415,36 @@ BOOL isRemoteInteropTest(NSString *host) {
- (void)testCancelAfterFirstResponseRPC {
XCTAssertNotNil(self.class.host);
- __weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterFirstResponse"];
+ __weak XCTestExpectation *expectation =
+ [self expectationWithDescription:@"CancelAfterFirstResponse"];
// A buffered pipe to which we write a single value but never close
GRXBufferedPipe *requestsBuffer = [[GRXBufferedPipe alloc] init];
__block BOOL receivedResponse = NO;
- id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:@21782
- requestedResponseSize:@31415];
+ id request =
+ [RMTStreamingOutputCallRequest messageWithPayloadSize:@21782 requestedResponseSize:@31415];
[requestsBuffer writeValue:request];
- __block GRPCProtoCall *call =
- [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer
- eventHandler:^(BOOL done,
- RMTStreamingOutputCallResponse *response,
- NSError *error) {
- if (receivedResponse) {
- XCTAssert(done, @"Unexpected extra response %@", response);
- XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
- [expectation fulfill];
- } else {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssertFalse(done, @"Finished without response");
- XCTAssertNotNil(response);
- receivedResponse = YES;
- [call cancel];
- }
- }];
+ __block GRPCProtoCall *call = [_service
+ RPCToFullDuplexCallWithRequestsWriter:requestsBuffer
+ eventHandler:^(BOOL done, RMTStreamingOutputCallResponse *response,
+ NSError *error) {
+ if (receivedResponse) {
+ XCTAssert(done, @"Unexpected extra response %@", response);
+ XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
+ [expectation fulfill];
+ } else {
+ XCTAssertNil(error, @"Finished with unexpected error: %@",
+ error);
+ XCTAssertFalse(done, @"Finished without response");
+ XCTAssertNotNil(response);
+ receivedResponse = YES;
+ [call cancel];
+ }
+ }];
[call start];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -439,19 +456,25 @@ BOOL isRemoteInteropTest(NSString *host) {
GPBEmpty *request = [GPBEmpty message];
- [_service emptyCallWithRequest:request handler:^(GPBEmpty *response, NSError *error) {
- XCTAssertNil(error, @"First RPC finished with unexpected error: %@", error);
+ [_service
+ emptyCallWithRequest:request
+ handler:^(GPBEmpty *response, NSError *error) {
+ XCTAssertNil(error, @"First RPC finished with unexpected error: %@", error);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- [GRPCCall closeOpenConnections];
+ [GRPCCall closeOpenConnections];
#pragma clang diagnostic pop
- [_service emptyCallWithRequest:request handler:^(GPBEmpty *response, NSError *error) {
- XCTAssertNil(error, @"Second RPC finished with unexpected error: %@", error);
- [expectation fulfill];
- }];
- }];
+ [_service
+ emptyCallWithRequest:request
+ handler:^(GPBEmpty *response, NSError *error) {
+ XCTAssertNil(
+ error, @"Second RPC finished with unexpected error: %@",
+ error);
+ [expectation fulfill];
+ }];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -472,16 +495,17 @@ BOOL isRemoteInteropTest(NSString *host) {
request.expectCompressed.value = YES;
[GRPCCall setDefaultCompressMethod:GRPCCompressGzip forhost:self.class.host];
- [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ [_service unaryCallWithRequest:request
+ handler:^(RMTSimpleResponse *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
- expectedResponse.payload.type = RMTPayloadType_Compressable;
- expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
- XCTAssertEqualObjects(response, expectedResponse);
+ RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
+ expectedResponse.payload.type = RMTPayloadType_Compressable;
+ expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
+ XCTAssertEqualObjects(response, expectedResponse);
- [expectation fulfill];
- }];
+ [expectation fulfill];
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
@@ -493,8 +517,8 @@ BOOL isRemoteInteropTest(NSString *host) {
[GRPCCall setKeepaliveWithInterval:1500 timeout:0 forHost:self.class.host];
- NSArray *requests = @[@27182, @8];
- NSArray *responses = @[@31415, @9];
+ NSArray *requests = @[ @27182, @8 ];
+ NSArray *responses = @[ @31415, @9 ];
GRXBufferedPipe *requestsBuffer = [[GRXBufferedPipe alloc] init];
@@ -504,25 +528,26 @@ BOOL isRemoteInteropTest(NSString *host) {
requestedResponseSize:responses[index]];
[requestsBuffer writeValue:request];
- [_service fullDuplexCallWithRequestsWriter:requestsBuffer
- eventHandler:^(BOOL done,
- RMTStreamingOutputCallResponse *response,
- NSError *error) {
- if (index == 0) {
- XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- XCTAssertTrue(response, @"Event handler called without an event.");
- XCTAssertFalse(done);
- index++;
- } else {
- // Keepalive should kick after 1s elapsed and fails the call.
- XCTAssertNotNil(error);
- XCTAssertEqual(error.code, GRPC_STATUS_INTERNAL);
- XCTAssertEqualObjects(error.localizedDescription, @"keepalive watchdog timeout",
- @"Unexpected failure that is not keepalive watchdog timeout.");
- XCTAssertTrue(done);
- [expectation fulfill];
- }
- }];
+ [_service
+ fullDuplexCallWithRequestsWriter:requestsBuffer
+ eventHandler:^(BOOL done, RMTStreamingOutputCallResponse *response,
+ NSError *error) {
+ if (index == 0) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertTrue(response, @"Event handler called without an event.");
+ XCTAssertFalse(done);
+ index++;
+ } else {
+ // Keepalive should kick after 1s elapsed and fails the call.
+ XCTAssertNotNil(error);
+ XCTAssertEqual(error.code, GRPC_STATUS_INTERNAL);
+ XCTAssertEqualObjects(
+ error.localizedDescription, @"keepalive watchdog timeout",
+ @"Unexpected failure that is not keepalive watchdog timeout.");
+ XCTAssertTrue(done);
+ [expectation fulfill];
+ }
+ }];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
diff --git a/src/objective-c/tests/InteropTestsLocalCleartext.m b/src/objective-c/tests/InteropTestsLocalCleartext.m
index aba9868211..d49e875bd0 100644
--- a/src/objective-c/tests/InteropTestsLocalCleartext.m
+++ b/src/objective-c/tests/InteropTestsLocalCleartext.m
@@ -25,7 +25,7 @@
// in turn derived from environment variable of the same name.
#define NSStringize_helper(x) #x
#define NSStringize(x) @NSStringize_helper(x)
-static NSString * const kLocalCleartextHost = NSStringize(HOST_PORT_LOCAL);
+static NSString *const kLocalCleartextHost = NSStringize(HOST_PORT_LOCAL);
// The Protocol Buffers encoding overhead of local interop server. Acquired
// by experiment. Adjust this when server's proto file changes.
@@ -42,7 +42,7 @@ static int32_t kLocalInteropServerOverhead = 10;
}
- (int32_t)encodingOverhead {
- return kLocalInteropServerOverhead; // bytes
+ return kLocalInteropServerOverhead; // bytes
}
- (void)setUp {
diff --git a/src/objective-c/tests/InteropTestsLocalSSL.m b/src/objective-c/tests/InteropTestsLocalSSL.m
index 06176cc588..a8c4dc7dfd 100644
--- a/src/objective-c/tests/InteropTestsLocalSSL.m
+++ b/src/objective-c/tests/InteropTestsLocalSSL.m
@@ -24,7 +24,7 @@
// in turn derived from environment variable of the same name.
#define NSStringize_helper(x) #x
#define NSStringize(x) @NSStringize_helper(x)
-static NSString * const kLocalSSLHost = NSStringize(HOST_PORT_LOCALSSL);
+static NSString *const kLocalSSLHost = NSStringize(HOST_PORT_LOCALSSL);
// The Protocol Buffers encoding overhead of local interop server. Acquired
// by experiment. Adjust this when server's proto file changes.
@@ -41,7 +41,7 @@ static int32_t kLocalInteropServerOverhead = 10;
}
- (int32_t)encodingOverhead {
- return kLocalInteropServerOverhead; // bytes
+ return kLocalInteropServerOverhead; // bytes
}
- (void)setUp {
@@ -49,8 +49,8 @@ static int32_t kLocalInteropServerOverhead = 10;
// Register test server certificates and name.
NSBundle *bundle = [NSBundle bundleForClass:self.class];
- NSString *certsPath = [bundle pathForResource:@"TestCertificates.bundle/test-certificates"
- ofType:@"pem"];
+ NSString *certsPath =
+ [bundle pathForResource:@"TestCertificates.bundle/test-certificates" ofType:@"pem"];
[GRPCCall useTestCertsPath:certsPath testName:@"foo.test.google.fr" forHost:kLocalSSLHost];
}
@@ -60,7 +60,7 @@ static int32_t kLocalInteropServerOverhead = 10;
@try {
[GRPCCall useTestCertsPath:nil testName:nil forHost:nil];
XCTFail(@"Did not receive an exception when parameters are nil");
- } @catch(NSException *theException) {
+ } @catch (NSException *theException) {
NSLog(@"Received exception as expected: %@", theException.name);
}
}
diff --git a/src/objective-c/tests/InteropTestsRemote.m b/src/objective-c/tests/InteropTestsRemote.m
index f8133e8689..e5738aac73 100644
--- a/src/objective-c/tests/InteropTestsRemote.m
+++ b/src/objective-c/tests/InteropTestsRemote.m
@@ -25,7 +25,7 @@
// in turn derived from environment variable of the same name.
#define NSStringize_helper(x) #x
#define NSStringize(x) @NSStringize_helper(x)
-static NSString * const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE);
+static NSString *const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE);
// The Protocol Buffers encoding overhead of remote interop server. Acquired
// by experiment. Adjust this when server's proto file changes.
@@ -42,7 +42,7 @@ static int32_t kRemoteInteropServerOverhead = 12;
}
- (int32_t)encodingOverhead {
- return kRemoteInteropServerOverhead; // bytes
+ return kRemoteInteropServerOverhead; // bytes
}
@end
diff --git a/src/objective-c/tests/InteropTestsRemoteWithCronet/InteropTestsRemoteWithCronet.m b/src/objective-c/tests/InteropTestsRemoteWithCronet/InteropTestsRemoteWithCronet.m
index d4eb5223fc..25041ae5eb 100644
--- a/src/objective-c/tests/InteropTestsRemoteWithCronet/InteropTestsRemoteWithCronet.m
+++ b/src/objective-c/tests/InteropTestsRemoteWithCronet/InteropTestsRemoteWithCronet.m
@@ -28,8 +28,7 @@
// in turn derived from environment variable of the same name.
#define NSStringize_helper(x) #x
#define NSStringize(x) @NSStringize_helper(x)
-static NSString * const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE);
-
+static NSString *const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE);
// The Protocol Buffers encoding overhead of remote interop server. Acquired
// by experiment. Adjust this when server's proto file changes.
@@ -46,7 +45,7 @@ static int32_t kRemoteInteropServerOverhead = 12;
}
- (int32_t)encodingOverhead {
- return kRemoteInteropServerOverhead; // bytes
+ return kRemoteInteropServerOverhead; // bytes
}
@end
diff --git a/src/objective-c/tests/RxLibraryUnitTests.m b/src/objective-c/tests/RxLibraryUnitTests.m
index aa178f8d45..ecd914c9b5 100644
--- a/src/objective-c/tests/RxLibraryUnitTests.m
+++ b/src/objective-c/tests/RxLibraryUnitTests.m
@@ -30,10 +30,10 @@
//
// TODO(jcanizales): Move this to a test util library, and add tests for it.
@interface CapturingSingleValueHandler : NSObject
-@property (nonatomic, readonly) void (^block)(id value, NSError *errorOrNil);
-@property (nonatomic, readonly) NSUInteger timesCalled;
-@property (nonatomic, readonly) id value;
-@property (nonatomic, readonly) NSError *errorOrNil;
+@property(nonatomic, readonly) void (^block)(id value, NSError *errorOrNil);
+@property(nonatomic, readonly) NSUInteger timesCalled;
+@property(nonatomic, readonly) id value;
+@property(nonatomic, readonly) NSError *errorOrNil;
+ (instancetype)handler;
@end
@@ -149,10 +149,11 @@
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Response received"];
// Given:
CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
- id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
- handler.block(value, errorOrNil);
- [expectation fulfill];
- }];
+ id<GRXWriteable> writeable =
+ [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
+ handler.block(value, errorOrNil);
+ [expectation fulfill];
+ }];
id anyValue = @7;
@@ -167,17 +168,17 @@
XCTAssertEqual(handler.timesCalled, 1);
XCTAssertEqualObjects(handler.value, anyValue);
XCTAssertEqualObjects(handler.errorOrNil, nil);
-
}
- (void)testBufferedPipePropagatesError {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Response received"];
// Given:
CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
- id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
- handler.block(value, errorOrNil);
- [expectation fulfill];
- }];
+ id<GRXWriteable> writeable =
+ [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
+ handler.block(value, errorOrNil);
+ [expectation fulfill];
+ }];
NSError *anyError = [NSError errorWithDomain:@"domain" code:7 userInfo:nil];
// If:
@@ -196,10 +197,11 @@
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Response received"];
// Given:
CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
- id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
- handler.block(value, errorOrNil);
- [expectation fulfill];
- }];
+ id<GRXWriteable> writeable =
+ [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
+ handler.block(value, errorOrNil);
+ [expectation fulfill];
+ }];
id anyValue = @7;
// If:
@@ -220,8 +222,9 @@
#define WRITE_ROUNDS (1000)
- (void)testBufferedPipeResumeWhenDealloc {
id anyValue = @7;
- id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
- }];
+ id<GRXWriteable> writeable =
+ [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil){
+ }];
// Release after alloc;
GRXBufferedPipe *pipe = [GRXBufferedPipe pipe];
diff --git a/src/objective-c/tests/version.h b/src/objective-c/tests/version.h
index 15fe1a59f3..d36545fced 100644
--- a/src/objective-c/tests/version.h
+++ b/src/objective-c/tests/version.h
@@ -22,6 +22,5 @@
// instead. This file can be regenerated from the template by running
// `tools/buildgen/generate_projects.sh`.
-
#define GRPC_OBJC_VERSION_STRING @"1.12.0-dev"
#define GRPC_C_VERSION_STRING @"6.0.0-dev"