diff options
author | Michael Lumish <mlumish@google.com> | 2017-06-13 17:27:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-13 17:27:56 -0700 |
commit | 596c05a3244cb84c846faa33030cc46eb6dfd0af (patch) | |
tree | 0d265422f48d4c9cf2bd6ef76cf3fe1ed62f33e6 | |
parent | b2eceb167d87b6d0c99c863250004b3f4f0a11d6 (diff) | |
parent | bf91d9bbf74c8b923d41643868adbd2105954e81 (diff) |
Merge pull request #11452 from murgatroid99/node_reconnect_test
Node: add test for reconnecting client after server restart
-rw-r--r-- | src/node/test/surface_test.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index f8eaf62aaf..11577e797d 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -1378,3 +1378,50 @@ describe('Cancelling surface client', function() { call.cancel(); }); }); +describe('Client reconnect', function() { + var server; + var Client; + var client; + var port; + beforeEach(function() { + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto'); + var echo_service = test_proto.lookup('EchoService'); + Client = grpc.loadObject(echo_service); + server = new grpc.Server(); + server.addService(Client.service, { + echo: function(call, callback) { + callback(null, call.request); + } + }); + port = server.bind('localhost:0', server_insecure_creds); + client = new Client('localhost:' + port, grpc.credentials.createInsecure()); + server.start(); + }); + afterEach(function() { + server.forceShutdown(); + }); + it('should reconnect after server restart', function(done) { + client.echo({value: 'test value', value2: 3}, function(error, response) { + assert.ifError(error); + assert.deepEqual(response, {value: 'test value', value2: 3}); + server.tryShutdown(function() { + server = new grpc.Server(); + server.addService(Client.service, { + echo: function(call, callback) { + callback(null, call.request); + } + }); + server.bind('localhost:' + port, server_insecure_creds); + server.start(); + client.echo(undefined, function(error, response) { + if (error) { + console.log(error); + } + assert.ifError(error); + assert.deepEqual(response, {value: '', value2: 0}); + done(); + }); + }); + }); + }); +}); |