Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: third_party/grpc/src/node/test/server_test.js

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 'use strict';
35
36 var assert = require('assert');
37 var fs = require('fs');
38 var path = require('path');
39 var grpc = require('../src/grpc_extension');
40
41 describe('server', function() {
42 describe('constructor', function() {
43 it('should work with no arguments', function() {
44 assert.doesNotThrow(function() {
45 new grpc.Server();
46 });
47 });
48 it('should work with an empty object argument', function() {
49 assert.doesNotThrow(function() {
50 new grpc.Server({});
51 });
52 });
53 it('should work without the new keyword', function() {
54 var server;
55 assert.doesNotThrow(function() {
56 server = grpc.Server();
57 });
58 assert(server instanceof grpc.Server);
59 });
60 it('should only accept objects with string or int values', function() {
61 assert.doesNotThrow(function() {
62 new grpc.Server({'key' : 'value'});
63 });
64 assert.doesNotThrow(function() {
65 new grpc.Server({'key' : 5});
66 });
67 assert.throws(function() {
68 new grpc.Server({'key' : null});
69 });
70 assert.throws(function() {
71 new grpc.Server({'key' : new Date()});
72 });
73 });
74 });
75 describe('addHttp2Port', function() {
76 var server;
77 before(function() {
78 server = new grpc.Server();
79 });
80 it('should bind to an unused port', function() {
81 var port;
82 assert.doesNotThrow(function() {
83 port = server.addHttp2Port('0.0.0.0:0',
84 grpc.ServerCredentials.createInsecure());
85 });
86 assert(port > 0);
87 });
88 it('should bind to an unused port with ssl credentials', function() {
89 var port;
90 var key_path = path.join(__dirname, '../test/data/server1.key');
91 var pem_path = path.join(__dirname, '../test/data/server1.pem');
92 var key_data = fs.readFileSync(key_path);
93 var pem_data = fs.readFileSync(pem_path);
94 var creds = grpc.ServerCredentials.createSsl(null,
95 [{private_key: key_data,
96 cert_chain: pem_data}]);
97 assert.doesNotThrow(function() {
98 port = server.addHttp2Port('0.0.0.0:0', creds);
99 });
100 assert(port > 0);
101 });
102 });
103 describe('addSecureHttp2Port', function() {
104 var server;
105 before(function() {
106 server = new grpc.Server();
107 });
108 });
109 describe('start', function() {
110 var server;
111 before(function() {
112 server = new grpc.Server();
113 server.addHttp2Port('0.0.0.0:0', grpc.ServerCredentials.createInsecure());
114 });
115 after(function() {
116 server.forceShutdown();
117 });
118 it('should start without error', function() {
119 assert.doesNotThrow(function() {
120 server.start();
121 });
122 });
123 });
124 describe('shutdown', function() {
125 var server;
126 beforeEach(function() {
127 server = new grpc.Server();
128 server.addHttp2Port('0.0.0.0:0', grpc.ServerCredentials.createInsecure());
129 server.start();
130 });
131 afterEach(function() {
132 server.forceShutdown();
133 });
134 it('tryShutdown should shutdown successfully', function(done) {
135 server.tryShutdown(done);
136 });
137 it('forceShutdown should shutdown successfully', function() {
138 server.forceShutdown();
139 });
140 it('tryShutdown should be idempotent', function(done) {
141 server.tryShutdown(done);
142 server.tryShutdown(function() {});
143 });
144 it('forceShutdown should be idempotent', function() {
145 server.forceShutdown();
146 server.forceShutdown();
147 });
148 it('forceShutdown should trigger tryShutdown', function(done) {
149 server.tryShutdown(done);
150 server.forceShutdown();
151 });
152 });
153 });
OLDNEW
« no previous file with comments | « third_party/grpc/src/node/test/numbers.txt ('k') | third_party/grpc/src/node/test/surface_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698