Skip to content

Commit

Permalink
Re-add "Fix Grpc-Message decoding (#117)" (#178)
Browse files Browse the repository at this point in the history
* Re-add "Fix Grpc-Message decoding (#117)"

This reverts commit 9df9c0a.

* Fixed clientWebsocket tests
  • Loading branch information
easyCZ authored and MarcusLongmuir committed May 1, 2018
1 parent fb9ccd3 commit 81ebe17
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 69 deletions.
100 changes: 52 additions & 48 deletions test/go/_proto/improbable/grpcweb/test/test.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion test/go/testserver/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ func (s *testSrv) PingError(ctx context.Context, ping *testproto.PingRequest) (*
if ping.GetSendTrailers() {
grpc.SetTrailer(ctx, metadata.Pairs("TrailerTestKey1", "ServerValue1", "TrailerTestKey2", "ServerValue2"))
}
return nil, grpc.Errorf(codes.Code(ping.ErrorCodeReturned), "Intentionally returning error for PingError")
if ping.FailureType == testproto.PingRequest_CODE {
return nil, grpc.Errorf(codes.Code(ping.ErrorCodeReturned), "Intentionally returning error for PingError")
} else {
return nil, grpc.Errorf(codes.Code(ping.ErrorCodeReturned), "💣")
}
}

func (s *testSrv) ContinueStream(ctx context.Context, req *testproto.ContinueStreamRequest) (*google_protobuf.Empty, error) {
Expand Down
1 change: 1 addition & 0 deletions test/proto/improbable/grpcweb/test/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ message PingRequest {
NONE = 0;
CODE = 1;
DROP = 2;
CODE_UNICODE = 3;
}

string value = 1;
Expand Down
1 change: 1 addition & 0 deletions test/ts/_proto/improbable/grpcweb/test/test_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export namespace PingRequest {
NONE = 0,
CODE = 1,
DROP = 2,
CODE_UNICODE = 3,
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/ts/_proto/improbable/grpcweb/test/test_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ proto.improbable.grpcweb.test.PingRequest.serializeBinaryToWriter = function(mes
proto.improbable.grpcweb.test.PingRequest.FailureType = {
NONE: 0,
CODE: 1,
DROP: 2
DROP: 2,
CODE_UNICODE: 3
};

/**
Expand Down
48 changes: 43 additions & 5 deletions test/ts/src/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ conditionallyRunTestSuite(SuiteEnum.client, () => {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.isNotOk(statusMessage, "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -161,7 +161,7 @@ conditionallyRunTestSuite(SuiteEnum.client, () => {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.isNotOk(statusMessage, "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -209,7 +209,7 @@ conditionallyRunTestSuite(SuiteEnum.client, () => {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.isNotOk(statusMessage, "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -260,7 +260,7 @@ conditionallyRunTestSuite(SuiteEnum.client, () => {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.isNotOk(statusMessage, "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -305,7 +305,7 @@ conditionallyRunTestSuite(SuiteEnum.client, () => {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.isNotOk(statusMessage, "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -357,6 +357,44 @@ conditionallyRunTestSuite(SuiteEnum.client, () => {
});
});

headerTrailerCombos((withHeaders, withTrailers) => {
it(`should report status code in Unicode for error with headers + trailers`, (done) => {
let didGetOnHeaders = false;
let didGetOnMessage = false;

const ping = new PingRequest();
ping.setFailureType(PingRequest.FailureType.CODE_UNICODE);
ping.setErrorCodeReturned(12);
ping.setSendHeaders(withHeaders);
ping.setSendTrailers(withTrailers);

const client = grpc.client(TestService.PingError, {
debug: DEBUG,
transport: transport,
host: testHostUrl,
});
client.onHeaders((headers: grpc.Metadata) => {
DEBUG && debug("headers", headers);
didGetOnHeaders = true;
});
client.onMessage((message: Empty) => {
didGetOnMessage = true;
});
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
assert.deepEqual(trailers.get("grpc-status"), ["12"]);
assert.deepEqual(trailers.get("grpc-message"), [encodeURIComponent("💣")]);
assert.strictEqual(status, grpc.Code.Unimplemented);
assert.strictEqual(statusMessage, "💣");
assert.ok(didGetOnHeaders);
assert.ok(!didGetOnMessage);
done();
});
client.start();
client.send(ping);
});
});

if (!process.env.DISABLE_CORS_TESTS) {
it(`should report failure for a CORS failure`, (done) => {
let didGetOnHeaders = false;
Expand Down
6 changes: 3 additions & 3 deletions test/ts/src/client.websocket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (process.env.DISABLE_WEBSOCKET_TESTS) {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.strictEqual(statusMessage, "", "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -113,7 +113,7 @@ if (process.env.DISABLE_WEBSOCKET_TESTS) {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.strictEqual(statusMessage, "", "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down Expand Up @@ -175,7 +175,7 @@ if (process.env.DISABLE_WEBSOCKET_TESTS) {
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage);
assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
assert.strictEqual(statusMessage, undefined, "expected no message");
assert.strictEqual(statusMessage, "", "expected no message");
if (withTrailers) {
assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
Expand Down
Loading

0 comments on commit 81ebe17

Please sign in to comment.