Skip to content

Commit e323df6

Browse files
committed
Create tests for conn.callTimeout
1 parent ee1ad0a commit e323df6

File tree

3 files changed

+204
-2
lines changed

3 files changed

+204
-2
lines changed

test/callTimeout.js

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 222. callTimeout.js
23+
*
24+
* DESCRIPTION
25+
* Test "Connection.callTimeout" property.
26+
*
27+
*****************************************************************************/
28+
'use strict';
29+
30+
const oracledb = require('oracledb');
31+
const should = require('should');
32+
const assert = require('assert');
33+
const dbconfig = require('./dbconfig.js');
34+
const testsUtil = require('./testsUtil.js');
35+
36+
describe('222. callTimeout.js', () => {
37+
38+
let isRunnable = true;
39+
let conn;
40+
41+
before(async function() {
42+
const isRunnable = await testsUtil.checkPrerequisites();
43+
if (!isRunnable) {
44+
this.skip();
45+
return;
46+
} else {
47+
conn = await oracledb.getConnection(dbconfig);
48+
}
49+
}); // before()
50+
51+
after(async function() {
52+
if (!isRunnable) {
53+
this.skip();
54+
return;
55+
} else {
56+
await conn.close();
57+
}
58+
});
59+
60+
it('222.1 examples/calltimeout.js', async () => {
61+
try {
62+
const TIME_OUT = 2;
63+
const DB_OP_TIME = 4;
64+
65+
conn.callTimeout = TIME_OUT * 1000; // milliseconds
66+
67+
await assert.rejects(
68+
async () => {
69+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
70+
},
71+
/ORA-03156/
72+
);
73+
/*
74+
expect - DPI-1067: call timeout of %u ms exceeded with ORA-%d
75+
actual - ORA-03156: OCI call timed out
76+
*/
77+
} catch (err) {
78+
should.not.exist(err);
79+
}
80+
81+
}); // 222.1
82+
83+
it('222.2 the timeout value is greater than the operation time', async () => {
84+
try {
85+
const TIME_OUT = 10;
86+
const DB_OP_TIME = 2;
87+
88+
conn.callTimeout = TIME_OUT * 1000; // milliseconds
89+
90+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
91+
92+
} catch (err) {
93+
should.not.exist(err);
94+
}
95+
}); // 222.2
96+
97+
it('222.3 callTimeout is 0', async () => {
98+
try {
99+
const TIME_OUT = 0;
100+
const DB_OP_TIME = 2;
101+
102+
conn.callTimeout = TIME_OUT;
103+
104+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
105+
} catch (err) {
106+
should.not.exist(err);
107+
}
108+
}); // 222.3
109+
110+
it('222.4 callTimeout is a negative value', async () => {
111+
try {
112+
const TIME_OUT = -5;
113+
114+
should.throws(
115+
() => {
116+
conn.callTimeout = TIME_OUT;
117+
},
118+
"NJS-004: invalid value for property callTimeout"
119+
);
120+
} catch (err) {
121+
should.not.exist(err);
122+
}
123+
}); // 222.4
124+
125+
it('222.5 callTimeout == NaN', async () => {
126+
try {
127+
const TIME_OUT = NaN;
128+
129+
should.throws(
130+
() => {
131+
conn.callTimeout = TIME_OUT;
132+
},
133+
"NJS-004: invalid value for property callTimeout"
134+
);
135+
} catch (err) {
136+
should.not.exist(err);
137+
}
138+
});
139+
140+
it('222.6 callTimeout is a String', async () => {
141+
try {
142+
const TIME_OUT = 'foobar';
143+
144+
should.throws(
145+
() => {
146+
conn.callTimeout = TIME_OUT;
147+
},
148+
"NJS-004: invalid value for property callTimeout"
149+
);
150+
} catch (err) {
151+
should.not.exist(err);
152+
}
153+
});
154+
155+
it('222.7 The callTimeout value applies not to the sum of all round-trips', async () => {
156+
try {
157+
const TIME_OUT = 4;
158+
159+
conn.callTimeout = TIME_OUT * 1000; // milliseconds
160+
161+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [2]);
162+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [3]);
163+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [2]);
164+
} catch (err) {
165+
should.not.exist(err);
166+
}
167+
}); // 222.7
168+
169+
it('The callTimeout value applies to each round-trip individually', async () => {
170+
try {
171+
const TIME_OUT = 2;
172+
const DB_OP_TIME = 4;
173+
174+
conn.callTimeout = TIME_OUT * 1000; // milliseconds
175+
176+
await assert.rejects(
177+
async () => {
178+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [DB_OP_TIME]);
179+
},
180+
/ORA-03156/
181+
);
182+
183+
await conn.execute(`BEGIN DBMS_SESSION.SLEEP(:sleepsec); END;`, [1]);
184+
let result = await conn.execute(`SELECT (1+2) AS SUM FROM DUAL`);
185+
should.strictEqual(3, result.rows[0][0]);
186+
187+
} catch (err) {
188+
should.not.exist(err);
189+
}
190+
});
191+
});

test/list.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4620,4 +4620,14 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
46204620

46214621
221. connectionClass.js
46224622
221.1 set the property when using a connection pool
4623-
221.2 set the property when using a standalone connection
4623+
221.2 set the property when using a standalone connection
4624+
4625+
222. callTimeout.js
4626+
222.1 examples/calltimeout.js
4627+
222.2 the timeout value is greater than the operation time
4628+
222.3 callTimeout is 0
4629+
222.4 callTimeout is a negative value
4630+
222.5 callTimeout == NaN
4631+
222.6 callTimeout is a String
4632+
222.7 The callTimeout value applies not to the sum of all round-trips
4633+
The callTimeout value applies to each round-trip individually

test/opts/mocha.opts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,5 @@ test/aq2.js
246246
test/aq3.js
247247

248248
test/examineOwnedProperties.js
249-
test/connectionClass.js
249+
test/connectionClass.js
250+
test/callTimeout.js

0 commit comments

Comments
 (0)