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
|
// **********************************************************************
//
// Copyright (c) 2003-2017 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)
{
var Ice = require("ice").Ice;
var Test = require("Test").Test;
var Promise = Ice.Promise;
var allTests = function(out, communicator)
{
var failCB = function() { test(false); };
var ref, obj, mult, timeout, to, connection, comm, now;
var p = new Promise();
var test = function(b)
{
if(!b)
{
try
{
throw new Error("test failed");
}
catch(err)
{
p.reject(err);
throw err;
}
}
};
var seq;
Promise.try(() =>
{
ref = "timeout:default -p 12010";
obj = communicator.stringToProxy(ref);
test(obj !== null);
mult = 1;
if(communicator.getProperties().getPropertyWithDefault("Ice.Default.Protocol", "tcp") === "ssl" ||
communicator.getProperties().getPropertyWithDefault("Ice.Default.Protocol", "tcp") === "wss")
{
mult = 4;
}
return Test.TimeoutPrx.checkedCast(obj);
}
).then(obj =>
{
timeout = obj;
test(timeout !== null);
out.write("testing connect timeout... ");
to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(100 * mult));
return timeout.holdAdapter(1000 * mult);
}
).then(() => to.ice_getConnection()
).then(() => to.op() // Expect ConnectTimeoutException.
).then(
failCB,
ex =>
{
test(ex instanceof Ice.ConnectTimeoutException);
return timeout.op(); // Ensure adapter is active.
}
).then(() =>
{
to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(1000 * mult));
return timeout.holdAdapter(500 * mult);
}
).then(() => to.ice_getConnection()
).then(() => to.op() // Expect success.
).then(() =>
{
out.writeLine("ok");
out.write("testing connection timeout... ");
to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(100 * mult));
seq = Ice.Buffer.createNative(new Array(10000000));
return timeout.holdAdapter(1000 * mult);
}
).then(() => to.sendData(seq) // Expect TimeoutException
).then(() => test(false),
ex =>
{
test(ex instanceof Ice.TimeoutException);
return timeout.op(); // Ensure adapter is active.
}
).then(() =>
{
// NOTE: 30s timeout is necessary for Firefox/IE on Windows
to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(30000 * mult));
return timeout.holdAdapter(500 * mult);
}
).then(() => to.sendData(Ice.Buffer.createNative(new Array(5 * 1024))) // Expect success.
).then(() =>
{
out.writeLine("ok");
out.write("testing invocation timeout... ");
return obj.ice_getConnection();
}
).then(con =>
{
to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(100));
return to.ice_getConnection();
}
).then(con =>
{
test(to.ice_getCachedConnection() === obj.ice_getCachedConnection());
return to.sleep(750);
}
).then(
failCB,
ex =>
{
test(ex instanceof Ice.InvocationTimeoutException);
return obj.ice_ping();
}
).then(() =>
{
to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(500));
return to.ice_getConnection();
}
).then(con =>
{
test(to.ice_getCachedConnection() === obj.ice_getCachedConnection());
return to.sleep(250);
}
).then(() =>
{
out.writeLine("ok");
out.write("testing close timeout... ");
to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(500));
return to.ice_getConnection();
}
).then(con =>
{
connection = con;
return timeout.holdAdapter(1500);
}
).then(() => connection.close(Ice.ConnectionClose.GracefullyWithWait)
).then(() =>
{
try
{
connection.getInfo(); // getInfo() doesn't throw in the closing state
}
catch(ex)
{
test(false);
}
}
).delay(1000).then(() =>
{
try
{
connection.getInfo();
test(false);
}
catch(ex)
{
test(ex instanceof Ice.ConnectionManuallyClosedException); // Expected
}
return timeout.op();
}
).then(() =>
{
out.writeLine("ok");
out.write("testing timeout overrides... ");
//
// Test Ice.Override.Timeout. This property overrides all
// endpoint timeouts.
//
var initData = new Ice.InitializationData();
initData.properties = communicator.getProperties().clone();
if(mult === 1)
{
initData.properties.setProperty("Ice.Override.Timeout", "100");
}
else
{
initData.properties.setProperty("Ice.Override.Timeout", "2000");
}
comm = Ice.initialize(initData);
return Test.TimeoutPrx.checkedCast(comm.stringToProxy(ref));
}
).then(obj =>
{
to = obj;
return timeout.holdAdapter(750 * 2 * mult);
}
).then(() => to.sendData(seq) // Expect TimeoutException.
).then(
failCB,
ex =>
{
test(ex instanceof Ice.TimeoutException);
return timeout.op(); // Ensure adapter is active.
}
).then(() => Test.TimeoutPrx.checkedCast(to.ice_timeout(1000 * mult)) // Calling ice_timeout() should have no effect.
).then(obj =>
{
to = obj;
return timeout.holdAdapter(750 * 2 * mult);
}
).then(() => to.sendData(seq) // Expect TimeoutException.
).then(
failCB,
ex =>
{
test(ex instanceof Ice.TimeoutException);
return comm.destroy();
}
).then(() =>
{
//
// Test Ice.Override.ConnectTimeout.
//
var 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");
}
comm = Ice.initialize(initData);
to = Test.TimeoutPrx.uncheckedCast(comm.stringToProxy(ref));
return timeout.holdAdapter(750 * mult);
}
).then(() => to.op()
).then(
failCB,
ex =>
{
test(ex instanceof Ice.ConnectTimeoutException);
return timeout.op(); // Ensure adapter is active.
}
).then(() => timeout.holdAdapter(750 * mult)
).then(() =>
{
//
// Calling ice_timeout() should have no effect on the connect timeout.
//
to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(1000 * mult));
return to.op();
}
).then(() => test(false),
ex =>
{
test(ex instanceof Ice.ConnectTimeoutException);
return timeout.op(); // Ensure adapter is active.
}
).then(() =>
{
to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(100 * mult));
return to.ice_getConnection(); // Force connection.
}
).then(obj => timeout.holdAdapter(750 * mult)
).then(() => to.sendData(seq)
).then(
failCB,
ex =>
{
test(ex instanceof Ice.TimeoutException);
return comm.destroy();
}
).then(() =>
{
//
// Test Ice.Override.CloseTimeout.
//
var initData = new Ice.InitializationData();
initData.properties = communicator.getProperties().clone();
initData.properties.setProperty("Ice.Override.CloseTimeout", "100");
comm = Ice.initialize(initData);
return comm.stringToProxy(ref).ice_getConnection();
}
).then(() => timeout.holdAdapter(500)
).then(() =>
{
now = Date.now();
return comm.destroy();
}
).then(() =>
{
var t = Date.now();
test(t - now < 400);
out.writeLine("ok");
return timeout.shutdown();
}
).then(p.resolve, p.reject);
return p;
};
var run = function(out, id)
{
//
// For this test, we want to disable retries.
//
id.properties.setProperty("Ice.RetryIntervals", "-1");
//
// We don't want connection warnings because of the timeout
//
id.properties.setProperty("Ice.Warn.Connections", "0");
//
// We need to send messages large enough to cause the transport
// buffers to fill up.
//
id.properties.setProperty("Ice.MessageSizeMax", "10000");
var c = Ice.initialize(id);
return Promise.try(() =>
{
if(typeof(navigator) !== 'undefined' && isSafari() && isWorker())
{
out.writeLine("Test not supported with Safari web workers.");
return Test.TimeoutPrx.uncheckedCast(c.stringToProxy("timeout:default -p 12010")).shutdown();
}
else
{
return allTests(out, c);
}
}
).finally(() => c.destroy());
};
exports._test = run;
exports._runServer = true;
}
(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));
|