Merge pull request #6386 from jcanizales/fix-call-state

Fix call state
pull/6391/merge
makdharma 9 years ago
commit 6b1afe1ad9
  1. 54
      src/objective-c/GRPCClient/GRPCCall.m
  2. 6
      src/objective-c/tests/InteropTests.m

@ -136,6 +136,10 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
#pragma mark Finish
- (void)finishWithError:(NSError *)errorOrNil {
@synchronized(self) {
_state = GRXWriterStateFinished;
}
// If the call isn't retained anywhere else, it can be deallocated now.
_retainSelf = nil;
@ -342,6 +346,10 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
#pragma mark GRXWriter implementation
- (void)startWithWriteable:(id<GRXWriteable>)writeable {
@synchronized(self) {
_state = GRXWriterStateStarted;
}
// Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled).
// This makes RPCs in which the call isn't externally retained possible (as long as it is started
// before being autoreleased).
@ -375,30 +383,32 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
}
- (void)setState:(GRXWriterState)newState {
// Manual transitions are only allowed from the started or paused states.
if (_state == GRXWriterStateNotStarted || _state == GRXWriterStateFinished) {
return;
}
switch (newState) {
case GRXWriterStateFinished:
_state = newState;
// Per GRXWriter's contract, setting the state to Finished manually
// means one doesn't wish the writeable to be messaged anymore.
[_responseWriteable cancelSilently];
_responseWriteable = nil;
return;
case GRXWriterStatePaused:
_state = newState;
@synchronized(self) {
// Manual transitions are only allowed from the started or paused states.
if (_state == GRXWriterStateNotStarted || _state == GRXWriterStateFinished) {
return;
case GRXWriterStateStarted:
if (_state == GRXWriterStatePaused) {
}
switch (newState) {
case GRXWriterStateFinished:
_state = newState;
[self startNextRead];
}
return;
case GRXWriterStateNotStarted:
return;
// Per GRXWriter's contract, setting the state to Finished manually
// means one doesn't wish the writeable to be messaged anymore.
[_responseWriteable cancelSilently];
_responseWriteable = nil;
return;
case GRXWriterStatePaused:
_state = newState;
return;
case GRXWriterStateStarted:
if (_state == GRXWriterStatePaused) {
_state = newState;
[self startNextRead];
}
return;
case GRXWriterStateNotStarted:
return;
}
}
}

@ -272,8 +272,14 @@
XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
[expectation fulfill];
}];
XCTAssertEqual(call.state, GRXWriterStateNotStarted);
[call start];
XCTAssertEqual(call.state, GRXWriterStateStarted);
[call cancel];
XCTAssertEqual(call.state, GRXWriterStateFinished);
[self waitForExpectationsWithTimeout:1 handler:nil];
}

Loading…
Cancel
Save