-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathpoolPing.js
276 lines (241 loc) · 8.55 KB
/
poolPing.js
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
/* Copyright (c) 2016, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 73. poolPing.js
*
* DESCRIPTION
* Testing connection ping feature of Pool object.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
describe("73. poolPing.js", function() {
const defaultInterval = oracledb.poolPingInterval;
afterEach("reset poolPingInterval to default", function() {
oracledb.poolPingInterval = defaultInterval;
});
it("73.1 the default value of poolPingInterval is 60", async function() {
const defaultValue = 60;
assert.strictEqual(oracledb.poolPingInterval, defaultValue);
const pool = await oracledb.createPool(dbConfig);
assert.strictEqual(pool.poolPingInterval, defaultValue);
await pool.close(0);
}); // 73.1
it("73.2 does not change after the pool has been created", async function() {
const userSetInterval = 20;
oracledb.poolPingInterval = userSetInterval;
const pool = await oracledb.createPool(dbConfig);
assert.strictEqual(pool.poolPingInterval, userSetInterval);
const newInterval = userSetInterval * 2;
oracledb.poolPingInterval = newInterval;
await new Promise((resolve) => setTimeout(resolve, 100));
assert.strictEqual(pool.poolPingInterval, userSetInterval);
await pool.close(0);
}); // 73.2
it("73.3 can not be changed on pool object", async function() {
const userSetInterval = 30;
oracledb.poolPingInterval = userSetInterval;
const pool = await oracledb.createPool(dbConfig);
assert.strictEqual(pool.poolPingInterval, userSetInterval);
const newInterval = userSetInterval * 2;
assert.throws(
() => pool.poolPingInterval = newInterval,
/TypeError/
);
await pool.close(0);
}); // 73.3
it("73.4 can not be accessed on connection object", async function() {
const pool = await oracledb.createPool(dbConfig);
const conn = await pool.getConnection();
assert.strictEqual(conn.poolPingInterval, undefined);
await conn.close();
await pool.close(0);
}); // 73.4
// helper function for below test cases
const testDefine = async function(userSetInterval) {
oracledb.poolPingInterval = userSetInterval;
const pool = await oracledb.createPool(dbConfig);
assert.strictEqual(pool.poolPingInterval, userSetInterval);
await pool.close(0);
}; // testDefine()
it("73.5 can be set to 0, means always ping", async function() {
await testDefine(0);
}); // 73.5
it("73.6 can be set to negative values, means never ping", async function() {
await testDefine(-80);
}); // 73.6
it("73.7 Negative: Number.MAX_SAFE_INTEGER", function() {
assert.throws(
() => oracledb.poolPingInterval = Number.MAX_SAFE_INTEGER,
/NJS-004:/
);
}); // 73.7
it("73.8 cannot surpass the upper limit", async function() {
const upperLimit = 2147483647; // 2GB
await testDefine(upperLimit);
assert.throws(
() => oracledb.poolPingInterval = upperLimit + 1,
/NJS-004:/
);
}); // 73.8
it("73.9 cannot surpass the lower Limit", async function() {
const lowerLimit = -2147483648;
await testDefine(lowerLimit);
assert.throws(
() => oracledb.poolPingInterval = lowerLimit - 1,
/NJS-004:/
);
}); // 73.9
it("73.10 Negative: null", function() {
assert.throws(
() => oracledb.poolPingInterval = null,
/NJS-004:/
);
}); // 73.10
it("73.11 Negative: NaN", function() {
assert.throws(
() => oracledb.poolPingInterval = NaN,
/NJS-004:/
);
}); // 73.11
it("73.12 Negative: undefined", function() {
assert.throws(
() => oracledb.poolPingInterval = undefined,
/NJS-004:/
);
}); // 73.12
it("73.13 Negative: 'random-string'", function() {
assert.throws(
() => oracledb.poolPingInterval = "random-string",
/NJS-004:/
);
}); // 73.13
const testPoolDefine = async function(userSetInterval, expectedValue) {
const config = {
user: dbConfig.user,
password: dbConfig.password,
connectString: dbConfig.connectString,
poolPingInterval: userSetInterval
};
const pool = await oracledb.createPool(config);
assert.strictEqual(pool.poolPingInterval, expectedValue);
await pool.close(0);
}; // testPoolDefine
it("73.14 can be set at pool creation, e.g. positive value 1234", async function() {
const userSetValue = 1234;
await testPoolDefine(userSetValue, userSetValue);
});
it("73.15 can be set at pool creation, e.g. negative value -4321", async function() {
const userSetValue = -4321;
await testPoolDefine(userSetValue, userSetValue);
});
it("73.16 can be set at pool creation, e.g. 0 means always ping", async function() {
const userSetValue = 0;
await testPoolDefine(userSetValue, userSetValue);
});
it("73.17 Negative: null", async function() {
oracledb.poolPingInterval = 789;
const config = {...dbConfig, poolPingInterval: null};
await assert.rejects(
async () => await oracledb.createPool(config),
/NJS-007:/
);
});
it("73.18 Setting to 'undefined' will use current value from oracledb", async function() {
oracledb.poolPingInterval = 9876;
const userSetValue = undefined;
await testPoolDefine(userSetValue, oracledb.poolPingInterval);
});
it("73.19 can be set at pool creation. Negative: NaN", async function() {
const config = {...dbConfig, poolPingInterval: NaN};
await assert.rejects(
async () => await oracledb.createPool(config),
/NJS-007:/
);
}); // 73.19
it("73.20 can be set at pool creation. Negative: 'random-string'", async function() {
const config = {...dbConfig, poolPingInterval: "random-string"};
await assert.rejects(
async () => await oracledb.createPool(config),
/NJS-007:/
);
}); // 73.20
it("73.21 cannot surpass the upper limit at pool creation", async function() {
const upperLimit = 2147483647; // 2GB
await testPoolDefine(upperLimit, upperLimit);
const config = {...dbConfig, poolPingInterval: upperLimit + 1};
await assert.rejects(
async () => await oracledb.createPool(config),
/NJS-007:/
);
}); // 73.21
it("73.22 cannot surpass the lower limit at pool creation", async function() {
const lowerLimit = -2147483648;
await testPoolDefine(lowerLimit, lowerLimit);
const config = {...dbConfig, poolPingInterval: lowerLimit - 1};
await assert.rejects(
async () => await oracledb.createPool(config),
/NJS-007:/
);
}); // 73.22
});
describe('73_1 poolPingTimeout', function() {
let newSessions = 0, pool;
afterEach(async function() {
if (pool) {
await pool.close(0);
pool = null;
}
});
function newSessionHandler(_, __, cb) {
newSessions += 1;
cb();
}
it('73_1.1 larger pingTimeout to simulate healthy conns',
async function() {
const largePingTimeout = 240000; // 4 min
const iter = 3;
newSessions = 0;
const config = {
...dbConfig,
poolMin: 0,
poolMax: 1,
poolIncrement: 1,
poolTimeout: 10,
poolPingInterval: 0, // always do pool ping
sessionCallback: newSessionHandler
};
oracledb.poolPingTimeout = largePingTimeout;
pool = await oracledb.createPool(config);
assert.strictEqual(pool.poolPingTimeout, largePingTimeout);
let conn;
for (let i = 0; i < iter; ++i) {
conn = await pool.getConnection();
await conn.close();
}
assert.strictEqual(newSessions, 1);
});
});