2023-02-21 14:42:17 +08:00
|
|
|
/* Copyright (c) 2016, 2023, Oracle and/or its affiliates. */
|
2017-06-14 09:54:45 +08:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* 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.
|
2017-06-14 09:54:45 +08:00
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* 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.
|
2017-06-14 09:54:45 +08:00
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2017-06-14 09:54:45 +08:00
|
|
|
*
|
2023-02-21 09:43:43 +08:00
|
|
|
* 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.
|
2017-06-14 09:54:45 +08:00
|
|
|
* 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';
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
const oracledb = require('oracledb');
|
2023-02-21 11:45:10 +08:00
|
|
|
const assert = require('assert');
|
2023-02-21 11:27:04 +08:00
|
|
|
const dbConfig = require('./dbconfig.js');
|
2017-06-14 09:54:45 +08:00
|
|
|
|
|
|
|
describe("73. poolPing.js", function() {
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
const defaultInterval = oracledb.poolPingInterval;
|
2017-06-14 09:54:45 +08:00
|
|
|
|
|
|
|
afterEach("reset poolPingInterval to default", function() {
|
|
|
|
oracledb.poolPingInterval = defaultInterval;
|
|
|
|
});
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
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);
|
2023-02-21 14:42:17 +08:00
|
|
|
await pool.close(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.1
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.2 does not change after the pool has been created", async function() {
|
|
|
|
const userSetInterval = 20;
|
2017-06-14 09:54:45 +08:00
|
|
|
oracledb.poolPingInterval = userSetInterval;
|
2023-02-21 11:27:04 +08:00
|
|
|
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);
|
2023-02-21 14:42:17 +08:00
|
|
|
await pool.close(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.2
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.3 can not be changed on pool object", async function() {
|
|
|
|
const userSetInterval = 30;
|
2017-06-14 09:54:45 +08:00
|
|
|
oracledb.poolPingInterval = userSetInterval;
|
2023-02-21 11:27:04 +08:00
|
|
|
const pool = await oracledb.createPool(dbConfig);
|
|
|
|
assert.strictEqual(pool.poolPingInterval, userSetInterval);
|
|
|
|
const newInterval = userSetInterval * 2;
|
|
|
|
assert.throws(
|
|
|
|
() => pool.poolPingInterval = newInterval,
|
|
|
|
/TypeError/
|
|
|
|
);
|
2023-02-21 14:42:17 +08:00
|
|
|
await pool.close(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.3
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
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();
|
2023-02-21 14:42:17 +08:00
|
|
|
await pool.close(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.4
|
|
|
|
|
|
|
|
// helper function for below test cases
|
2023-02-21 11:27:04 +08:00
|
|
|
const testDefine = async function(userSetInterval) {
|
2017-06-14 09:54:45 +08:00
|
|
|
oracledb.poolPingInterval = userSetInterval;
|
2023-02-21 11:27:04 +08:00
|
|
|
const pool = await oracledb.createPool(dbConfig);
|
|
|
|
assert.strictEqual(pool.poolPingInterval, userSetInterval);
|
2023-02-21 14:42:17 +08:00
|
|
|
await pool.close(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}; // testDefine()
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.5 can be set to 0, means always ping", async function() {
|
|
|
|
await testDefine(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.5
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.6 can be set to negative values, means never ping", async function() {
|
|
|
|
await testDefine(-80);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.6
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.7 Negative: Number.MAX_SAFE_INTEGER", function() {
|
|
|
|
assert.throws(
|
|
|
|
() => oracledb.poolPingInterval = Number.MAX_SAFE_INTEGER,
|
|
|
|
/NJS-004:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.7
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
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:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.8
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.9 cannot surpass the lower Limit", async function() {
|
|
|
|
const lowerLimit = -2147483648;
|
|
|
|
await testDefine(lowerLimit);
|
|
|
|
assert.throws(
|
|
|
|
() => oracledb.poolPingInterval = lowerLimit - 1,
|
|
|
|
/NJS-004:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.9
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.10 Negative: null", function() {
|
|
|
|
assert.throws(
|
|
|
|
() => oracledb.poolPingInterval = null,
|
|
|
|
/NJS-004:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.10
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.11 Negative: NaN", function() {
|
|
|
|
assert.throws(
|
|
|
|
() => oracledb.poolPingInterval = NaN,
|
|
|
|
/NJS-004:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.11
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.12 Negative: undefined", function() {
|
|
|
|
assert.throws(
|
|
|
|
() => oracledb.poolPingInterval = undefined,
|
|
|
|
/NJS-004:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.12
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.13 Negative: 'random-string'", function() {
|
|
|
|
assert.throws(
|
|
|
|
() => oracledb.poolPingInterval = "random-string",
|
|
|
|
/NJS-004:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.13
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
const testPoolDefine = async function(userSetInterval, expectedValue) {
|
|
|
|
const config = {
|
2023-10-30 22:47:16 +08:00
|
|
|
user: dbConfig.user,
|
|
|
|
password: dbConfig.password,
|
|
|
|
connectString: dbConfig.connectString,
|
2023-02-21 11:27:04 +08:00
|
|
|
poolPingInterval: userSetInterval
|
|
|
|
};
|
|
|
|
const pool = await oracledb.createPool(config);
|
|
|
|
assert.strictEqual(pool.poolPingInterval, expectedValue);
|
2023-02-21 14:42:17 +08:00
|
|
|
await pool.close(0);
|
2017-06-14 09:54:45 +08:00
|
|
|
}; // testPoolDefine
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.14 can be set at pool creation, e.g. positive value 1234", async function() {
|
|
|
|
const userSetValue = 1234;
|
|
|
|
await testPoolDefine(userSetValue, userSetValue);
|
2017-06-14 09:54:45 +08:00
|
|
|
});
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.15 can be set at pool creation, e.g. negative value -4321", async function() {
|
|
|
|
const userSetValue = -4321;
|
|
|
|
await testPoolDefine(userSetValue, userSetValue);
|
2017-06-14 09:54:45 +08:00
|
|
|
});
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.16 can be set at pool creation, e.g. 0 means always ping", async function() {
|
|
|
|
const userSetValue = 0;
|
|
|
|
await testPoolDefine(userSetValue, userSetValue);
|
2017-06-14 09:54:45 +08:00
|
|
|
});
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.17 Negative: null", async function() {
|
2017-06-14 09:54:45 +08:00
|
|
|
oracledb.poolPingInterval = 789;
|
2023-02-21 11:27:04 +08:00
|
|
|
const config = {...dbConfig, poolPingInterval: null};
|
2023-02-21 11:45:10 +08:00
|
|
|
await assert.rejects(
|
2023-02-21 11:27:04 +08:00
|
|
|
async () => await oracledb.createPool(config),
|
|
|
|
/NJS-007:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
});
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.18 Setting to 'undefined' will use current value from oracledb", async function() {
|
2017-06-14 09:54:45 +08:00
|
|
|
oracledb.poolPingInterval = 9876;
|
2023-02-21 11:27:04 +08:00
|
|
|
const userSetValue = undefined;
|
|
|
|
await testPoolDefine(userSetValue, oracledb.poolPingInterval);
|
2017-06-14 09:54:45 +08:00
|
|
|
});
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.19 can be set at pool creation. Negative: NaN", async function() {
|
|
|
|
const config = {...dbConfig, poolPingInterval: NaN};
|
2023-02-21 11:45:10 +08:00
|
|
|
await assert.rejects(
|
2023-02-21 11:27:04 +08:00
|
|
|
async () => await oracledb.createPool(config),
|
|
|
|
/NJS-007:/
|
2017-06-14 09:54:45 +08:00
|
|
|
);
|
|
|
|
}); // 73.19
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
it("73.20 can be set at pool creation. Negative: 'random-string'", async function() {
|
|
|
|
const config = {...dbConfig, poolPingInterval: "random-string"};
|
2023-02-21 11:45:10 +08:00
|
|
|
await assert.rejects(
|
2023-02-21 11:27:04 +08:00
|
|
|
async () => await oracledb.createPool(config),
|
|
|
|
/NJS-007:/
|
2017-06-14 09:54:45 +08:00
|
|
|
);
|
|
|
|
}); // 73.20
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
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};
|
2023-02-21 11:45:10 +08:00
|
|
|
await assert.rejects(
|
2023-02-21 11:27:04 +08:00
|
|
|
async () => await oracledb.createPool(config),
|
|
|
|
/NJS-007:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.21
|
|
|
|
|
2023-02-21 11:27:04 +08:00
|
|
|
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};
|
2023-02-21 11:45:10 +08:00
|
|
|
await assert.rejects(
|
2023-02-21 11:27:04 +08:00
|
|
|
async () => await oracledb.createPool(config),
|
|
|
|
/NJS-007:/
|
|
|
|
);
|
2017-06-14 09:54:45 +08:00
|
|
|
}); // 73.22
|
|
|
|
|
|
|
|
});
|
2024-01-30 19:06:31 +08:00
|
|
|
|
|
|
|
describe('73_1 poolPingTimeout', function() {
|
|
|
|
let newSessions = 0, pool;
|
|
|
|
|
|
|
|
afterEach(async function() {
|
|
|
|
if (pool) {
|
|
|
|
await pool.close(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|