Skip to content

Commit

Permalink
Log full Status on Android test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ejona86 committed Feb 4, 2016
1 parent 3d3fd11 commit 5a5f985
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ public void cancelAfterBegin() throws Exception {
requestObserver.onError(new RuntimeException());
assertTrue(responseObserver.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertEquals(Arrays.<StreamingInputCallResponse>asList(), responseObserver.getValues());
assertEquals(io.grpc.Status.CANCELLED.getCode(),
io.grpc.Status.fromThrowable(responseObserver.getError()).getCode());
assertCodeEquals(io.grpc.Status.CANCELLED,
io.grpc.Status.fromThrowable(responseObserver.getError()));
}

public void cancelAfterFirstResponse() throws Exception {
Expand Down Expand Up @@ -431,8 +431,7 @@ public void cancelAfterFirstResponse() throws Exception {
if (!(response instanceof Throwable)) {
fail("Unexpected: " + response);
}
assertEquals(io.grpc.Status.CANCELLED.getCode(),
io.grpc.Status.fromThrowable((Throwable) response).getCode());
assertCodeEquals(io.grpc.Status.CANCELLED, io.grpc.Status.fromThrowable((Throwable) response));
}

public void fullDuplexCallShouldSucceed() throws Exception {
Expand Down Expand Up @@ -557,7 +556,8 @@ public void onClose(io.grpc.Status status, Metadata trailers) {
call.request(1);
assertMessageEquals(goldenResponses[1],
(StreamingOutputCallResponse) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertEquals(io.grpc.Status.OK, queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertCodeEquals(io.grpc.Status.OK,
(io.grpc.Status) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
}

public void veryLargeRequest() throws Exception {
Expand Down Expand Up @@ -606,16 +606,15 @@ public void deadlineExceeded() {
blockingStub.emptyCall(new EmptyProtos.Empty());
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel)
.withDeadlineAfter(10, TimeUnit.MILLISECONDS);
StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseParameters = new ResponseParameters[1];
request.responseParameters[0] = new ResponseParameters();
request.responseParameters[0].intervalUs = 20000;
try {
StreamingOutputCallRequest request = new StreamingOutputCallRequest();
request.responseParameters = new ResponseParameters[1];
request.responseParameters[0] = new ResponseParameters();
request.responseParameters[0].intervalUs = 20000;
stub.streamingOutputCall(request).next();
fail("Expected deadline to be exceeded");
} catch (Throwable t) {
assertEquals(io.grpc.Status.DEADLINE_EXCEEDED.getCode(),
io.grpc.Status.fromThrowable(t).getCode());
} catch (StatusRuntimeException ex) {
assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, ex.getStatus());
}
}

Expand All @@ -637,8 +636,8 @@ public void deadlineExceededServerStreaming() throws Exception {
.withDeadlineAfter(30, TimeUnit.MILLISECONDS)
.streamingOutputCall(request, recorder);
assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertEquals(io.grpc.Status.DEADLINE_EXCEEDED.getCode(),
io.grpc.Status.fromThrowable(recorder.getError()).getCode());
assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED,
io.grpc.Status.fromThrowable(recorder.getError()));
}

protected int unaryPayloadLength() {
Expand Down Expand Up @@ -713,7 +712,7 @@ public void unimplementedMethod() {
stub.unimplementedCall(new EmptyProtos.Empty());
fail();
} catch (StatusRuntimeException e) {
assertEquals(io.grpc.Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode());
assertCodeEquals(io.grpc.Status.UNIMPLEMENTED, e.getStatus());
}
}

Expand All @@ -735,8 +734,8 @@ public void timeoutOnSleepingServer() throws Exception {
}

assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertEquals(io.grpc.Status.DEADLINE_EXCEEDED.getCode(),
io.grpc.Status.fromThrowable(recorder.getError()).getCode());
assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED,
io.grpc.Status.fromThrowable(recorder.getError()));
}

public static void assertMessageEquals(MessageNano expected, MessageNano actual) {
Expand Down Expand Up @@ -770,6 +769,15 @@ public static void assertMessageEquals(List<? extends MessageNano> expected,
}
}

private static void assertCodeEquals(io.grpc.Status expected, io.grpc.Status actual) {
if (expected == null) {
fail("expected should not be null");
}
if (actual == null || !expected.getCode().equals(actual.getCode())) {
assertEquals(expected, actual);
}
}

private SSLSocketFactory getSslSocketFactory(@Nullable InputStream testCa) throws Exception {
if (testCa == null) {
return (SSLSocketFactory) SSLSocketFactory.getDefault();
Expand Down

0 comments on commit 5a5f985

Please sign in to comment.