@@ -36,6 +36,7 @@ const assert = require('assert');
3636const fs = require ( 'fs' ) ;
3737const dbConfig = require ( './dbconfig.js' ) ;
3838const random = require ( './random.js' ) ;
39+ const testsUtil = require ( './testsUtil.js' ) ;
3940
4041describe ( '75. clobPlsqlBindAsString_bindout.js' , function ( ) {
4142
@@ -162,13 +163,17 @@ describe('75. clobPlsqlBindAsString_bindout.js', function() {
162163 "END nodb_clobs_out_741; " ;
163164 const sqlRun = "BEGIN nodb_clobs_out_741 (:i, :c); END;" ;
164165 const proc_drop = "DROP PROCEDURE nodb_clobs_out_741" ;
166+ let sysDBAConn ;
165167
166168 before ( async function ( ) {
167169 await connection . execute ( proc ) ;
168170 } ) ;
169171
170172 after ( async function ( ) {
171173 await connection . execute ( proc_drop ) ;
174+ if ( sysDBAConn ) {
175+ await sysDBAConn . close ( ) ;
176+ }
172177 } ) ;
173178
174179 it ( '75.1.1 works with EMPTY_LOB' , async function ( ) {
@@ -546,6 +551,51 @@ describe('75. clobPlsqlBindAsString_bindout.js', function() {
546551 ) ;
547552 } ) ; // 75.1.28
548553
554+ it ( '75.1.29 Verify Cursor leak is not there for Bind Error' , async function ( ) {
555+ if ( ! dbConfig . test . DBA_PRIVILEGE ) {
556+ this . skip ( ) ;
557+ }
558+ const len = 32769 ;
559+ const sequence = insertID ++ ;
560+ const specialStr = "75.1.24.1" ;
561+ const clobStr = random . getRandomString ( len , specialStr ) ;
562+ const bindVar = {
563+ i : { val : sequence , type : oracledb . NUMBER , dir : oracledb . BIND_IN } ,
564+ c : { type : oracledb . STRING , dir : oracledb . BIND_OUT , maxSize : len - 1 }
565+ } ;
566+ await insertClobWithString ( sequence , clobStr ) ;
567+
568+ // Remove the sqlRun statement from cache before checking leak.
569+ // It will also let server open any internal cursors for this statement
570+ // and hence the actual cursor count for this statement can be verified
571+ // after running in loop below.
572+ await assert . rejects (
573+ async ( ) => await connection . execute ( sqlRun , bindVar , { keepInStmtCache : false } ) ,
574+ / N J S - 0 1 6 : /
575+ ) ;
576+
577+ const sid = await testsUtil . getSid ( connection ) ;
578+ const dbaConfig = {
579+ user : dbConfig . test . DBA_user ,
580+ password : dbConfig . test . DBA_password ,
581+ connectionString : dbConfig . connectString ,
582+ privilege : oracledb . SYSDBA
583+ } ;
584+ sysDBAConn = await oracledb . getConnection ( dbaConfig ) ;
585+ const openCount = await testsUtil . getOpenCursorCount ( sysDBAConn , sid ) ;
586+
587+ // Running in loop should not result in opening more than 1 cursor
588+ // additionally on server.
589+ for ( let i = 0 ; i < 15 ; i ++ ) {
590+ await assert . rejects (
591+ async ( ) => await connection . execute ( sqlRun , bindVar ) ,
592+ / N J S - 0 1 6 : /
593+ ) ;
594+ }
595+ const newOpenCount = await testsUtil . getOpenCursorCount ( sysDBAConn , sid ) ;
596+ assert . strictEqual ( newOpenCount - openCount , 1 ) ;
597+ } ) ; // 75.1.29
598+
549599 } ) ; // 75.1
550600
551601 describe ( '75.2 CLOB, PLSQL, BIND_OUT to VARCHAR2' , function ( ) {
0 commit comments