2022-04-19 08:06:36 +08:00
|
|
|
/* Copyright (c) 2018, 2022, Oracle and/or its affiliates. */
|
2019-11-05 08:07:14 +08:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* You may not use the identified files except in compliance with the Apache
|
|
|
|
* License, Version 2.0 (the "License.")
|
|
|
|
*
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://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
|
|
|
|
* 222. callTimeout.js
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Test "Connection.callTimeout" property.
|
2019-11-26 05:23:16 +08:00
|
|
|
* This test requries NODE_ORACLEDB_QA environment variable to be true.
|
|
|
|
* Because test cases use the hard-code variables TIME_OUT and
|
|
|
|
* DB_OP_TIME which are not stable in all network situations.
|
2019-11-05 08:07:14 +08:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const oracledb = require('oracledb');
|
|
|
|
const assert = require('assert');
|
|
|
|
const dbconfig = require('./dbconfig.js');
|
|
|
|
const testsUtil = require('./testsUtil.js');
|
|
|
|
|
2019-11-05 08:24:10 +08:00
|
|
|
describe('222. callTimeout.js', function() {
|
2019-11-05 08:07:14 +08:00
|
|
|
|
|
|
|
let isRunnable = true;
|
|
|
|
let conn;
|
|
|
|
|
|
|
|
before(async function() {
|
2019-11-26 05:23:16 +08:00
|
|
|
|
|
|
|
const isQA = dbconfig.test.NODE_ORACLEDB_QA;
|
|
|
|
const prep = await testsUtil.checkPrerequisites();
|
|
|
|
isRunnable = isQA && prep;
|
2019-11-05 08:07:14 +08:00
|
|
|
if (!isRunnable) {
|
|
|
|
this.skip();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
conn = await oracledb.getConnection(dbconfig);
|
|
|
|
}
|
|
|
|
}); // before()
|
|
|
|
|
|
|
|
after(async function() {
|
|
|
|
if (!isRunnable) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
await conn.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('222.1 examples/calltimeout.js', async () => {
|
|
|
|
try {
|
|
|
|
const TIME_OUT = 2;
|
|
|
|
const DB_OP_TIME = 4;
|
|
|
|
|
|
|
|
conn.callTimeout = TIME_OUT * 1000; // milliseconds
|
|
|
|
|
|
|
|
await assert.rejects(
|
|
|
|
async () => {
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
|
|
|
|
},
|
2019-11-05 08:09:15 +08:00
|
|
|
/DPI-1067/
|
2019-11-05 08:07:14 +08:00
|
|
|
);
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}); // 222.1
|
|
|
|
|
|
|
|
it('222.2 the timeout value is greater than the operation time', async () => {
|
|
|
|
try {
|
|
|
|
const TIME_OUT = 10;
|
|
|
|
const DB_OP_TIME = 2;
|
|
|
|
|
|
|
|
conn.callTimeout = TIME_OUT * 1000; // milliseconds
|
|
|
|
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
|
|
|
|
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
}); // 222.2
|
|
|
|
|
|
|
|
it('222.3 callTimeout is 0', async () => {
|
|
|
|
try {
|
|
|
|
const TIME_OUT = 0;
|
|
|
|
const DB_OP_TIME = 2;
|
|
|
|
|
|
|
|
conn.callTimeout = TIME_OUT;
|
|
|
|
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
}); // 222.3
|
|
|
|
|
2021-04-01 12:48:37 +08:00
|
|
|
it('222.4 callTimeout is a negative value', function() {
|
2019-11-05 08:07:14 +08:00
|
|
|
try {
|
|
|
|
const TIME_OUT = -5;
|
|
|
|
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.throws(
|
2019-11-05 08:07:14 +08:00
|
|
|
() => {
|
|
|
|
conn.callTimeout = TIME_OUT;
|
|
|
|
},
|
2021-10-11 10:33:01 +08:00
|
|
|
/NJS-004: invalid value for property callTimeout/
|
2019-11-05 08:07:14 +08:00
|
|
|
);
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
}); // 222.4
|
|
|
|
|
2021-04-01 12:48:37 +08:00
|
|
|
it('222.5 callTimeout == NaN', function() {
|
2019-11-05 08:07:14 +08:00
|
|
|
try {
|
|
|
|
const TIME_OUT = NaN;
|
|
|
|
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.throws(
|
2019-11-05 08:07:14 +08:00
|
|
|
() => {
|
|
|
|
conn.callTimeout = TIME_OUT;
|
|
|
|
},
|
2021-10-11 10:33:01 +08:00
|
|
|
/NJS-004: invalid value for property callTimeout/
|
2019-11-05 08:07:14 +08:00
|
|
|
);
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-01 12:48:37 +08:00
|
|
|
it('222.6 callTimeout is a String', function() {
|
2019-11-05 08:07:14 +08:00
|
|
|
try {
|
|
|
|
const TIME_OUT = 'foobar';
|
|
|
|
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.throws(
|
2019-11-05 08:07:14 +08:00
|
|
|
() => {
|
|
|
|
conn.callTimeout = TIME_OUT;
|
|
|
|
},
|
2021-10-11 10:33:01 +08:00
|
|
|
/NJS-004: invalid value for property callTimeout/
|
2019-11-05 08:07:14 +08:00
|
|
|
);
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('222.7 The callTimeout value applies not to the sum of all round-trips', async () => {
|
|
|
|
try {
|
|
|
|
const TIME_OUT = 4;
|
|
|
|
|
|
|
|
conn.callTimeout = TIME_OUT * 1000; // milliseconds
|
|
|
|
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [2]);
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [3]);
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [2]);
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
}); // 222.7
|
|
|
|
|
2019-11-05 08:09:15 +08:00
|
|
|
it('222.8 The callTimeout value applies to each round-trip individually', async () => {
|
2019-11-05 08:07:14 +08:00
|
|
|
try {
|
|
|
|
const TIME_OUT = 2;
|
|
|
|
const DB_OP_TIME = 4;
|
|
|
|
|
|
|
|
conn.callTimeout = TIME_OUT * 1000; // milliseconds
|
|
|
|
|
|
|
|
await assert.rejects(
|
|
|
|
async () => {
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
|
|
|
|
},
|
2019-11-05 08:09:15 +08:00
|
|
|
/DPI-1067/
|
2019-11-05 08:07:14 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [1]);
|
2021-10-11 10:33:01 +08:00
|
|
|
const result = await conn.execute(`SELECT (1+2) AS SUM FROM DUAL`);
|
|
|
|
assert.strictEqual(3, result.rows[0][0]);
|
2019-11-05 08:07:14 +08:00
|
|
|
|
|
|
|
} catch (err) {
|
2021-10-11 10:33:01 +08:00
|
|
|
assert.fail(err);
|
2019-11-05 08:07:14 +08:00
|
|
|
}
|
|
|
|
});
|
2019-11-05 08:09:15 +08:00
|
|
|
});
|