node-oracledb/test/poolTimeout.js

198 lines
5.9 KiB
JavaScript
Raw Normal View History

/* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. */
2015-07-20 12:42:12 +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.
2016-03-24 14:09:53 +08:00
*
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
2015-07-20 12:42:12 +08:00
* See LICENSE.md for relevant licenses.
*
* NAME
* 11. poolTimeout.js
*
* DESCRIPTION
* Testing time-out property of pool.
*
* NUMBERING RULE
* Test numbers follow this numbering rule:
* 1 - 20 are reserved for basic functional tests
* 21 - 50 are reserved for data type supporting tests
* 51 onwards are for other tests
2016-03-24 14:09:53 +08:00
*
2015-07-20 12:42:12 +08:00
*****************************************************************************/
2016-05-16 07:57:53 +08:00
'use strict';
2015-07-20 12:42:12 +08:00
var oracledb = require('oracledb');
var should = require('should');
var async = require('async');
var dbConfig = require('./dbconfig.js');
2015-07-20 12:42:12 +08:00
describe('11. poolTimeout.js', function(){
2016-03-24 14:09:53 +08:00
2016-05-16 07:57:53 +08:00
this.timeout(0); // disable suite-level Time-out
var pool = null;
2016-03-24 14:09:53 +08:00
2015-07-20 12:42:12 +08:00
before(function(done){
oracledb.createPool(
{
2016-05-16 07:57:53 +08:00
externalAuth : dbConfig.externalAuth,
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString,
2015-07-20 12:42:12 +08:00
poolMin : 1,
poolMax : 5,
poolIncrement : 2,
poolTimeout : 2,
stmtCacheSize : 23
},
function(err, pooling){
if(err) { console.log(err.message); return; }
//console.log("---- Pool created.");
pool = pooling;
done();
}
2016-03-24 14:09:53 +08:00
);
2015-07-20 12:42:12 +08:00
})
2016-03-24 14:09:53 +08:00
2015-07-20 12:42:12 +08:00
after(function(done){
pool.terminate(function(err){
if(err) { console.log(err.message); return; }
//console.log("---- pool terminated.");
done();
2016-03-24 14:09:53 +08:00
});
2015-07-20 12:42:12 +08:00
})
2016-03-24 14:09:53 +08:00
it('11.1 pool terminates idle connections after specify time', function(done){
2015-07-20 12:42:12 +08:00
pool.should.be.ok;
2016-05-16 07:57:53 +08:00
if(!dbConfig.externalAuth){
pool.connectionsOpen.should.be.exactly(1).and.be.a.Number();
2015-07-20 12:42:12 +08:00
} else {
pool.connectionsOpen.should.be.exactly(0);
}
pool.connectionsInUse.should.be.exactly(0).and.be.a.Number();
2016-03-24 14:09:53 +08:00
2016-05-16 07:57:53 +08:00
var conn1 = null;
var conn2 = null;
var conn3 = null;
var conn4 = null;
2015-07-20 12:42:12 +08:00
async.series([
function(callback){
pool.getConnection( function(err, conn){
should.not.exist(err);
conn.should.be.ok;
conn1 = conn;
//console.log("-- create conn 1");
callback();
});
2016-03-24 14:09:53 +08:00
},
2015-07-20 12:42:12 +08:00
function(callback){
pool.connectionsOpen.should.be.exactly(1);
pool.connectionsInUse.should.be.exactly(1);
pool.getConnection( function(err, conn){
should.not.exist(err);
conn.should.be.ok;
conn2 = conn;
//console.log("-- create conn 2");
callback();
});
},
function(callback){
2016-05-16 07:57:53 +08:00
if(!dbConfig.externalAuth){
2015-07-20 12:42:12 +08:00
pool.connectionsOpen.should.be.exactly(3);
} else {
pool.connectionsOpen.should.be.exactly(2);
}
pool.connectionsInUse.should.be.exactly(2);
pool.getConnection( function(err, conn){
should.not.exist(err);
conn.should.be.ok;
conn3 = conn;
//console.log("-- create conn 3");
callback();
});
},
function(callback){
pool.connectionsOpen.should.be.exactly(3);
pool.connectionsInUse.should.be.exactly(3);
conn1.should.be.ok;
conn1.release( function(err){
should.not.exist(err);
//console.log("-- release conn 1");
callback();
});
},
function(callback){
pool.connectionsOpen.should.be.exactly(3);
pool.connectionsInUse.should.be.exactly(2);
conn2.should.be.ok;
conn2.release( function(err){
should.not.exist(err);
//console.log("-- release conn 2");
callback();
});
},
function(callback){
pool.connectionsOpen.should.be.exactly(3);
pool.connectionsInUse.should.be.exactly(1);
conn3.should.be.ok;
conn3.release( function(err){
should.not.exist(err);
//console.log("-- release conn 3");
callback();
});
},
function(callback){
setTimeout( function(){
/* Sleep over poolTimeout time */
//console.log("-- sleep over poolTimeout time");
pool.connectionsOpen.should.be.exactly(3);
pool.connectionsInUse.should.be.exactly(0);
//console.log("-- 7s later");
callback();
}, 7000);
},
function(callback){
pool.connectionsOpen.should.be.exactly(3);
pool.connectionsInUse.should.be.exactly(0);
pool.getConnection( function(err, conn){
should.not.exist(err);
conn.should.be.ok;
conn4 = conn;
//console.log("-- create conn 4");
callback();
});
},
function(callback){
/*11g client timeout idle connctions as part of session release */
//pool.connectionsOpen.should.be.exactly(3);
2016-03-24 14:09:53 +08:00
2015-07-20 12:42:12 +08:00
/*12c client is done as part of get connection*/
//pool.connectionsOpen.should.be.exactly(1);
2016-03-24 14:09:53 +08:00
2015-07-20 12:42:12 +08:00
pool.connectionsInUse.should.be.exactly(1);
conn4.should.be.ok;
conn4.release( function(err){
should.not.exist(err);
pool.connectionsOpen.should.be.exactly(1);
pool.connectionsInUse.should.be.exactly(0);
//console.log("-- release conn 4");
callback();
});
}
], done);
2016-03-24 14:09:53 +08:00
2015-07-20 12:42:12 +08:00
})
2016-03-24 14:09:53 +08:00
2015-07-20 12:42:12 +08:00
})