1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
// **********************************************************************
//
// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
(function(module, require, exports)
{
const Ice = require("ice").Ice;
const Test = require("Test").Test;
const TestHelper = require("TestHelper").TestHelper;
const test = TestHelper.test;
class Client extends TestHelper
{
async allTests()
{
async function connect(prx)
{
let nRetry = 10;
while(--nRetry > 0)
{
try
{
await prx.ice_getConnection();
break;
}
catch(ex)
{
// Can sporadically occur with slow machines
test(ex instanceof Ice.ConnectTimeoutException ||
ex instanceof Ice.ConnectFailedException, ex);
}
await Ice.Promise.delay(100);
}
return prx.ice_getConnection();
}
const communicator = this.communicator();
const out = this.getWriter();
const ref = "timeout:" + this.getTestEndpoint();
const obj = communicator.stringToProxy(ref);
test(obj !== null);
let mult = 1;
if(["ssl", "wss"].includes(
communicator.getProperties().getPropertyWithDefault("Ice.Default.Protocol", "tcp")))
{
mult = 4;
}
const timeout = await Test.TimeoutPrx.checkedCast(obj);
test(timeout !== null);
const controller = Test.ControllerPrx.uncheckedCast(
communicator.stringToProxy("controller:" + this.getTestEndpoint(1)));
test(controller !== null);
out.write("testing connect timeout... ");
{
const to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(100 * mult));
await controller.holdAdapter(-1);
try
{
await to.op(); // Expect ConnectTimeoutException.
test(false);
}
catch(ex)
{
test(ex instanceof Ice.ConnectTimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op(); // Ensure adapter is active.
}
{
const to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(-1));
await controller.holdAdapter(100 * mult);
await to.ice_getConnection();
try
{
await to.op(); // Expect success.
}
catch(ex)
{
test(false, ex);
}
}
out.writeLine("ok");
const seq = new Uint8Array(10000000);
out.write("testing connection timeout... ");
{
const to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(250 * mult));
await connect(to);
await controller.holdAdapter(-1);
try
{
await to.sendData(seq); // Expect TimeoutException
test(false);
}
catch(ex)
{
test(ex instanceof Ice.TimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op(); // Ensure adapter is active.
}
{
// NOTE: 30s timeout is necessary for Firefox/IE on Windows
const to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(30000 * mult));
await controller.holdAdapter(200 * mult);
try
{
await to.sendData(new Uint8Array(5 * 1024)); // Expect success.
}
catch(ex)
{
test(false, ex);
}
}
out.writeLine("ok");
out.write("testing invocation timeout... ");
{
const connection = await obj.ice_getConnection();
let to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(100));
test(connection == await to.ice_getConnection());
try
{
await to.sleep(500);
test(false);
}
catch(ex)
{
test(ex instanceof Ice.InvocationTimeoutException, ex);
}
await obj.ice_ping();
to = await Test.TimeoutPrx.checkedCast(obj.ice_invocationTimeout(1000));
test(connection === await obj.ice_getConnection());
try
{
await to.sleep(100);
}
catch(ex)
{
test(ex instanceof Ice.InvocationTimeoutException, ex);
}
}
out.writeLine("ok");
// Small delay is useful for IE which doesn't like too many connection failures in a row
await Ice.Promise.delay(500);
out.write("testing close timeout... ");
{
const to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(500));
const connection = await connect(to);
await controller.holdAdapter(-1);
await connection.close(Ice.ConnectionClose.GracefullyWithWait);
try
{
connection.getInfo(); // getInfo() doesn't throw in the closing state
}
catch(ex)
{
test(false, ex);
}
while(true)
{
try
{
connection.getInfo();
await Ice.Promise.delay(10);
}
catch(ex)
{
test(ex instanceof Ice.ConnectionManuallyClosedException, ex); // Expected
test(ex.graceful);
break;
}
}
await controller.resumeAdapter();
await timeout.op();
}
out.writeLine("ok");
// Small delay is useful for IE which doesn't like too many connection failures in a row
await Ice.Promise.delay(500);
out.write("testing timeout overrides... ");
{
//
// Test Ice.Override.Timeout. This property overrides all
// endpoint timeouts.
//
const initData = new Ice.InitializationData();
initData.properties = communicator.getProperties().clone();
if(mult === 1)
{
initData.properties.setProperty("Ice.Override.ConnectTimeout", "250");
initData.properties.setProperty("Ice.Override.Timeout", "100");
}
else
{
initData.properties.setProperty("Ice.Override.ConnectTimeout", "5000");
initData.properties.setProperty("Ice.Override.Timeout", "2000");
}
const comm = Ice.initialize(initData);
let to = Test.TimeoutPrx.uncheckedCast(comm.stringToProxy(ref));
await connect(to);
await controller.holdAdapter(-1);
try
{
await to.sendData(seq); // Expect TimeoutException.
test(false);
}
catch(ex)
{
test(ex instanceof Ice.TimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op();
//
// Calling ice_timeout() should have no effect.
//
to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(1000 * mult));
await connect(to);
await controller.holdAdapter(-1);
try
{
await to.sendData(seq); // Expect TimeoutException.
test(false);
}
catch(ex)
{
test(ex instanceof Ice.TimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op();
await comm.destroy();
}
// Small delay is useful for IE which doesn't like too many connection failures in a row
await Ice.Promise.delay(500);
{
//
// Test Ice.Override.ConnectTimeout.
//
const initData = new Ice.InitializationData();
initData.properties = communicator.getProperties().clone();
if(mult === 1)
{
initData.properties.setProperty("Ice.Override.ConnectTimeout", "250");
}
else
{
initData.properties.setProperty("Ice.Override.ConnectTimeout", "1000");
}
const comm = Ice.initialize(initData);
let to = Test.TimeoutPrx.uncheckedCast(comm.stringToProxy(ref));
await controller.holdAdapter(-1);
try
{
await to.op();
test(false);
}
catch(ex)
{
test(ex instanceof Ice.ConnectTimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op();
await controller.holdAdapter(-1);
//
// Calling ice_timeout() should have no effect on the connect timeout.
//
to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(1000 * mult));
try
{
await to.op();
test(false);
}
catch(ex)
{
test(ex instanceof Ice.ConnectTimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op(); // Ensure adapter is active
//
// Verify that timeout set via ice_timeout() is still used for requests.
//
to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(100 * mult));
await connect(to); // Force connection.
await controller.holdAdapter(-1);
try
{
await to.sendData(seq);
test(false);
}
catch(ex)
{
test(ex instanceof Ice.TimeoutException, ex);
}
await controller.resumeAdapter();
await timeout.op();
await comm.destroy();
}
// Small delay is useful for IE which doesn't like too many connection failures in a row
await Ice.Promise.delay(500);
{
//
// Test Ice.Override.CloseTimeout.
//
const initData = new Ice.InitializationData();
initData.properties = communicator.getProperties().clone();
initData.properties.setProperty("Ice.Override.CloseTimeout", "100");
const comm = Ice.initialize(initData);
await comm.stringToProxy(ref).ice_getConnection();
await controller.holdAdapter(-1);
const start = Date.now();
await comm.destroy();
const end = Date.now();
test(end - start < 1000);
await controller.resumeAdapter();
out.writeLine("ok");
await controller.shutdown();
}
}
async run(args)
{
let communicator;
try
{
const [properties] = this.createTestProperties(args);
//
// For this test, we want to disable retries.
//
properties.setProperty("Ice.RetryIntervals", "-1");
//
// We don't want connection warnings because of the timeout
//
properties.setProperty("Ice.Warn.Connections", "0");
properties.setProperty("Ice.PrintStackTraces", "1");
[communicator] = this.initialize(properties);
await this.allTests();
}
finally
{
if(communicator)
{
await communicator.destroy();
}
}
}
}
exports.Client = Client;
}(typeof global !== "undefined" && typeof global.process !== "undefined" ? module : undefined,
typeof global !== "undefined" && typeof global.process !== "undefined" ? require : this.Ice._require,
typeof global !== "undefined" && typeof global.process !== "undefined" ? exports : this));
|