Skip to content

Commit 6adbd12

Browse files
committed
Resolve a race condition in tests
1 parent ea5aaed commit 6adbd12

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

test/dataTypeAssist.js

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ assist.verifyRefCursor = function(connection, tableName, array, done)
742742

743743
function fetchRowsFromRS(rs, array, cb)
744744
{
745+
var numRows = 3;
745746
rs.getRows(numRows, function(err, rows) {
746747
if(rows.length > 0) {
747748
for(var i = 0; i < rows.length; i++) {
@@ -947,7 +948,7 @@ assist.verifyRefCursorWithFetchInfo = function(connection, tableName, array, don
947948
},
948949
function(err, result) {
949950
should.not.exist(err);
950-
fetchRowsFromRS_fetchas(connection, result.outBinds.out, array, tableName, callback);
951+
_verifyFetchedValues(connection, result.outBinds.out, array, tableName, callback);
951952
}
952953
);
953954
},
@@ -990,7 +991,7 @@ assist.verifyRefCursorWithFetchAsString = function(connection, tableName, array,
990991
{ outFormat: oracledb.OBJECT },
991992
function(err, result) {
992993
should.not.exist(err);
993-
fetchRowsFromRS_fetchas(connection, result.outBinds.out, array, tableName, callback);
994+
_verifyFetchedValues(connection, result.outBinds.out, array, tableName, callback);
994995
}
995996
);
996997
},
@@ -1006,40 +1007,34 @@ assist.verifyRefCursorWithFetchAsString = function(connection, tableName, array,
10061007
], done);
10071008
};
10081009

1009-
var numRows = 3; // number of rows to return from each call to getRows()
1010-
1011-
function fetchRowsFromRS_fetchas(connection, rs, array, tableName, cb) {
1012-
rs.getRows(numRows, function(err, rsrows) {
1013-
if(rsrows.length > 0) {
1014-
for(var i = 0; i < rsrows.length; i++) {
1015-
(rsrows[i].CONTENT).should.be.a.String();
1016-
verifyFetchValues(connection, rsrows, i, array, tableName);
1017-
}
1018-
return fetchRowsFromRS_fetchas(connection, rs, array, tableName, cb);
1019-
} else {
1020-
rs.close(function(err) {
1010+
var _verifyFetchedValues = function(connection, rs, array, tableName, cb) {
1011+
var amount = array.length;
1012+
rs.getRows(amount, function(err, rows) {
1013+
async.each(
1014+
rows,
1015+
queryAndCompare,
1016+
function(err) {
10211017
should.not.exist(err);
1022-
cb();
1023-
});
1024-
}
1018+
rs.close(function(err) {
1019+
should.not.exist(err);
1020+
return cb();
1021+
});
1022+
}
1023+
);
10251024
});
1026-
}
10271025

1028-
function verifyFetchValues(connection, rsrows, i, array, tableName){
1029-
connection.execute(
1030-
"select CONTENT from " + tableName + " where NUM = " + rsrows[i].NUM,
1031-
[],
1032-
{
1033-
fetchInfo:
1034-
{
1035-
"CONTENT": { type: oracledb.STRING }
1026+
var queryAndCompare = function(row, callback) {
1027+
var sql = "select content from " + tableName + " where num = " + row.NUM;
1028+
connection.execute(
1029+
sql,
1030+
[],
1031+
{ fetchInfo: { "CONTENT": { type: oracledb.STRING } } },
1032+
function(err, result) {
1033+
should.strictEqual(row.CONTENT, result.rows[0][0]);
1034+
return callback(err);
10361035
}
1037-
},
1038-
function(err, result) {
1039-
should.not.exist(err);
1040-
rsrows[i].CONTENT.should.eql(result.rows[0][0]);
1041-
}
1042-
);
1043-
}
1036+
);
1037+
};
1038+
}; // _verifyFetchedValues()
10441039

10451040
module.exports = assist;

test/dataTypeTimestamp2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('34. dataTypeTimestamp2.js', function() {
7575
});
7676

7777
after(function(done) {
78+
oracledb.fetchAsString = [];
7879
connection.execute(
7980
"DROP table " + tableName + " PURGE",
8081
function(err) {

0 commit comments

Comments
 (0)