Skip to content
Snippets Groups Projects
Commit 81b4fcbe authored by murgatroid99's avatar murgatroid99
Browse files

Added test for responseHeaders KVO compliance

parent 04715888
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,37 @@ static ProtoMethod *kInexistentMethod; ...@@ -53,6 +53,37 @@ static ProtoMethod *kInexistentMethod;
static ProtoMethod *kEmptyCallMethod; static ProtoMethod *kEmptyCallMethod;
static ProtoMethod *kUnaryCallMethod; static ProtoMethod *kUnaryCallMethod;
// This is an observer class for testing that responseMetadata is KVO-compliant
@interface PassthroughObserver : NSObject
- (instancetype) initWithCallback:(void (^)(NSString*, id, NSDictionary*))callback;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change
context:(void *)context;
@end
@implementation PassthroughObserver {
void (^_callback)(NSString*, id, NSDictionary*);
}
- (instancetype)initWithCallback:(void (^)(NSString *, id, NSDictionary *))callback {
self = [super init];
if (self) {
_callback = callback;
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
_callback(keyPath, object, change);
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@end
@interface GRPCClientTests : XCTestCase @interface GRPCClientTests : XCTestCase
@end @end
...@@ -183,4 +214,35 @@ static ProtoMethod *kUnaryCallMethod; ...@@ -183,4 +214,35 @@ static ProtoMethod *kUnaryCallMethod;
[self waitForExpectationsWithTimeout:4 handler:nil]; [self waitForExpectationsWithTimeout:4 handler:nil];
} }
- (void)testResponseMetadataKVO {
__weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
__weak XCTestExpectation *metadata = [self expectationWithDescription:@"Metadata changed."];
PassthroughObserver *observer = [[PassthroughObserver alloc] initWithCallback:^(NSString *keypath, id object, NSDictionary * change) {
if (keypath == @"responseHeaders") {
[expectation fulfill];
}
}]
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
path:kEmptyCallMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
[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];
}];
[call startWithWriteable:responsesWriteable];
[self waitForExpectationsWithTimeout:8 handler:nil];
}
@end @end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment