Skip to content

Commit 6efa57a

Browse files
committed
Tests for RS and LOB automatically close after conn closes
1 parent 097b735 commit 6efa57a

File tree

6 files changed

+85
-13
lines changed

6 files changed

+85
-13
lines changed

test/connection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,10 @@ describe('1. connection.js', function(){
798798
connectString: 'this is wrong',
799799
connectionString: dbConfig.connectString
800800
},
801-
function(err, connection) {
801+
function(err, conn) {
802802
should.exist(err);
803+
// ORA-12154: TNS:could not resolve the connect identifier specified
804+
should.not.exist(conn);
803805

804806
oracledb.getConnection(
805807
{

test/list.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Overview of node-oracledb functional tests
7070
2.10.1 close can be used as an alternative to release
7171
2.11 Invalid Credential
7272
2.11.1 error occurs at creating pool when poolMin >= 1
73-
2.11.2 error occurs at getConnection() when poolMin is the default value 1
73+
2.11.2 error occurs at getConnection() when poolMin is the default value 0
7474
2.12 connectionString alias
7575
2.12.1 allows connectionString to be used as an alias for connectString
7676
2.12.2 favors connectString if both connectString and connectionString are passed
@@ -824,6 +824,7 @@ Overview of node-oracledb functional tests
824824
54.1 can access properties of closed LOB without error
825825
54.2 can not call close() multiple times
826826
54.3 verify closed LOB
827+
54.4 automatically close result sets and LOBs when the connection is closed
827828

828829
55. resultSet2.js
829830
55.1 query a RDBMS function
@@ -833,9 +834,9 @@ Overview of node-oracledb functional tests
833834
55.3 alternating getRow() & getRows() function
834835
55.3.1 result set
835836
55.3.2 REF Cursor
836-
55.4 release connection before close resultSet
837-
55.4.1 result set
838-
55.4.2 REF Cursor
837+
55.4 automatically close result sets and LOBs when the connection is closed
838+
55.4.1 resultSet gets closed automatically
839+
55.4.2 REF Cursor gets closed automatically
839840
55.5 the content of resultSet should be consistent
840841
55.5.1 (1) get RS (2) modify data in that table and commit (3) check RS
841842
55.6 access resultSet simultaneously

test/lobClose.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -37,6 +37,7 @@ var oracledb = require('oracledb');
3737
var should = require('should');
3838
var dbConfig = require('./dbconfig.js');
3939
var fs = require('fs');
40+
var async = require('async');
4041

4142
describe('54. lobClose.js', function() {
4243

@@ -124,7 +125,6 @@ describe('54. lobClose.js', function() {
124125
});
125126

126127
lob.on("error", function(err) {
127-
//should.not.exist(err, "lob.on 'error' event.");
128128
should.strictEqual(
129129
err.message,
130130
"NJS-022: invalid Lob"
@@ -141,4 +141,64 @@ describe('54. lobClose.js', function() {
141141
);
142142
}); // 54.3
143143

144+
it('54.4 automatically close result sets and LOBs when the connection is closed', function(done) {
145+
146+
var conn2 = null;
147+
var lob2 = null;
148+
async.series([
149+
function creatConn(cb) {
150+
oracledb.getConnection(
151+
dbConfig,
152+
function(err, connection) {
153+
should.not.exist(err);
154+
conn2 = connection;
155+
cb();
156+
}
157+
);
158+
},
159+
function createLOB(cb) {
160+
conn2.createLob(
161+
oracledb.CLOB,
162+
function(err, lob) {
163+
should.not.exist(err);
164+
lob2 = lob;
165+
cb();
166+
}
167+
);
168+
},
169+
function closeConn(cb) {
170+
conn2.close(cb);
171+
},
172+
function dotest(cb) {
173+
// Verify that lob2 gets closed automatically
174+
var inFileName = './test/clobexample.txt';
175+
var inStream = fs.createReadStream(inFileName);
176+
inStream.pipe(lob2);
177+
178+
inStream.on("error", function(err) {
179+
should.not.exist(err, "inStream.on 'error' event.");
180+
});
181+
182+
lob2.on("error", function(err) {
183+
should.strictEqual(
184+
err.message,
185+
"DPI-1040: LOB was already closed"
186+
);
187+
cb();
188+
});
189+
190+
lob2.on('finish', function() {
191+
cb(new Error("LOB emits 'finish' event!"));
192+
});
193+
},
194+
function(cb) {
195+
(lob2.chunkSize).should.be.a.Number();
196+
(lob2.pieceSize).should.be.a.Number();
197+
should.strictEqual(lob2.length, 0);
198+
should.strictEqual(lob2.type, oracledb.CLOB);
199+
cb();
200+
}
201+
], done);
202+
}); // 54.4
203+
144204
});

test/pool.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ describe('2. pool.js', function() {
10101010
);
10111011
}); // 2.11.1
10121012

1013-
it('2.11.2 error occurs at getConnection() when poolMin is the default value 1', function(done) {
1013+
it('2.11.2 error occurs at getConnection() when poolMin is the default value 0', function(done) {
10141014
oracledb.createPool(
10151015
{
10161016
user: 'notexist',
@@ -1075,6 +1075,7 @@ describe('2. pool.js', function() {
10751075
},
10761076
function(err, pool) {
10771077
should.exist(err);
1078+
should.not.exist(pool);
10781079

10791080
oracledb.createPool(
10801081
{

test/resultSet2.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -262,7 +262,7 @@ describe('55. resultSet2.js', function() {
262262
});
263263
});
264264

265-
describe('55.4 release connection before close resultSet', function() {
265+
describe('55.4 automatically close result sets and LOBs when the connection is closed', function() {
266266
before(function(done){
267267
setUp(connection, tableName, done);
268268
});
@@ -304,7 +304,7 @@ describe('55. resultSet2.js', function() {
304304
});
305305
}
306306

307-
it('55.4.1 result set', function(done) {
307+
it('55.4.1 resultSet gets closed automatically', function(done) {
308308
testConn.should.be.ok();
309309
testConn.execute(
310310
"SELECT * FROM nodb_rs2_emp ORDER BY employees_id",
@@ -317,7 +317,7 @@ describe('55. resultSet2.js', function() {
317317
);
318318
});
319319

320-
it('55.4.2 REF Cursor', function(done) {
320+
it('55.4.2 REF Cursor gets closed automatically', function(done) {
321321
testConn.should.be.ok();
322322
testConn.execute(
323323
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
@@ -873,6 +873,7 @@ describe('55. resultSet2.js', function() {
873873
},
874874
function ( err ) {
875875
should.exist ( err );
876+
// ORA-24338: statement handle not executed
876877
done();
877878
}
878879
);

test/v8Getter.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ describe('140. v8Getter.js', function() {
544544
throw 'Nope';
545545
}
546546
});
547-
dotest(cred, done);
547+
548+
should.throws(
549+
function() {
550+
oracledb.createPool(cred, function() {});
551+
},
552+
/Nope/
553+
);
554+
done();
548555
});
549556

550557
it('140.7.4 poolMin', function(done) {

0 commit comments

Comments
 (0)