Skip to content

Commit 1f07b3d

Browse files
committed
Test accessing properties of closed objects
1 parent 83a738e commit 1f07b3d

File tree

5 files changed

+452
-194
lines changed

5 files changed

+452
-194
lines changed

test/connClose.js

Lines changed: 158 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535

3636
var oracledb = require('oracledb');
3737
var should = require('should');
38-
var async = require('async');
3938
var dbConfig = require('./dbconfig.js');
40-
var assist = require('./dataTypeAssist.js');
4139

4240
describe('52. connClose.js', function() {
4341

44-
it('52.1 can not set property value after connection closes', function(done) {
42+
it('52.1 can not set property, stmtCacheSize, after connection closes', function(done) {
4543
oracledb.getConnection(
4644
dbConfig,
4745
function(err, connection) {
@@ -63,22 +61,27 @@ describe('52. connClose.js', function() {
6361
);
6462
}); // 52.1
6563

66-
it('52.2 can not get property value after connection closes', function(done) {
64+
it('52.2 can not set property, clientId, after connection closes', function(done) {
6765
oracledb.getConnection(
6866
dbConfig,
6967
function(err, connection) {
7068
should.not.exist(err);
7169

7270
connection.release(function(err) {
7371
should.not.exist(err);
74-
should.strictEqual(connection.stmtCacheSize, undefined);
72+
should.throws(
73+
function() {
74+
connection.clientId = "52.3";
75+
},
76+
/NJS-003: invalid connection/
77+
);
7578
done();
7679
});
7780
}
7881
);
7982
}); // 52.2
8083

81-
it('52.3 can not set clientId property value', function(done) {
84+
it('52.3 can not set property, module', function(done) {
8285
oracledb.getConnection(
8386
dbConfig,
8487
function(err, connection) {
@@ -88,7 +91,7 @@ describe('52. connClose.js', function() {
8891
should.not.exist(err);
8992
should.throws(
9093
function() {
91-
connection.clientId = "52.3";
94+
connection.module = "52.4";
9295
},
9396
/NJS-003: invalid connection/
9497
);
@@ -98,7 +101,7 @@ describe('52. connClose.js', function() {
98101
);
99102
}); // 52.3
100103

101-
it('52.4 can not set module property value', function(done) {
104+
it('52.4 can not set property, action', function(done) {
102105
oracledb.getConnection(
103106
dbConfig,
104107
function(err, connection) {
@@ -108,7 +111,7 @@ describe('52. connClose.js', function() {
108111
should.not.exist(err);
109112
should.throws(
110113
function() {
111-
connection.module = "52.4";
114+
connection.module = "52.5";
112115
},
113116
/NJS-003: invalid connection/
114117
);
@@ -118,140 +121,193 @@ describe('52. connClose.js', function() {
118121
);
119122
}); // 52.4
120123

121-
it('52.5 can not set action property value', function(done) {
124+
it('52.5 can not call method, execute()', function(done) {
122125
oracledb.getConnection(
123126
dbConfig,
124127
function(err, connection) {
125128
should.not.exist(err);
126129

127130
connection.release(function(err) {
128131
should.not.exist(err);
129-
should.throws(
130-
function() {
131-
connection.module = "52.5";
132-
},
133-
/NJS-003: invalid connection/
132+
connection.execute(
133+
"select sysdate from dual",
134+
function(err, result) {
135+
should.not.exist(result);
136+
should.exist(err);
137+
should.strictEqual(
138+
err.message,
139+
"NJS-003: invalid connection"
140+
);
141+
done();
142+
}
134143
);
135-
done();
136144
});
137145
}
138146
);
139147
}); // 52.5
140148

141-
it('52.6 can not get oracleServerVersion property value', function(done) {
149+
it('52.6 can not call method, break()', function(done) {
142150
oracledb.getConnection(
143151
dbConfig,
144152
function(err, connection) {
145153
should.not.exist(err);
146154

147155
connection.release(function(err) {
148156
should.not.exist(err);
149-
should.strictEqual(connection.oracleServerVersion, undefined);
150-
done();
157+
158+
connection.break(function(err) {
159+
should.exist(err);
160+
should.strictEqual(
161+
err.message,
162+
"NJS-003: invalid connection"
163+
);
164+
done();
165+
});
151166
});
152167
}
153168
);
154169
}); // 52.6
155170

156-
it('52.7 can not call execute() method', function(done) {
171+
it('52.7 can not call method, commit()', function(done) {
157172
oracledb.getConnection(
158173
dbConfig,
159174
function(err, connection) {
160175
should.not.exist(err);
161176

162177
connection.release(function(err) {
163178
should.not.exist(err);
164-
connection.execute(
165-
"select sysdate from dual",
166-
function(err, result) {
167-
should.not.exist(result);
168-
should.exist(err);
169-
should.strictEqual(
170-
err.message,
171-
"NJS-003: invalid connection"
172-
);
173-
done();
174-
}
175-
);
179+
180+
connection.commit(function(err) {
181+
should.exist(err);
182+
should.strictEqual(
183+
err.message,
184+
"NJS-003: invalid connection"
185+
);
186+
done();
187+
});
176188
});
177189
}
178190
);
179191
}); // 52.7
180192

181-
it('52.8 can not get metaData property after connection closes', function(done) {
182-
var tableName = "nodb_number";
183-
var numbers = assist.data.numbers;
184-
var connection = null;
185-
var resultSet = null;
186-
187-
async.series([
188-
function getConn(callback) {
189-
oracledb.getConnection(
190-
dbConfig,
191-
function(err, conn) {
192-
should.not.exist(err);
193-
connection = conn;
194-
callback();
195-
}
196-
);
197-
},
198-
function(callback) {
199-
assist.setUp(connection, tableName, numbers, callback);
200-
},
201-
function getResultSet(callback) {
202-
connection.execute(
203-
"SELECT * FROM " + tableName + " ORDER BY num",
204-
[],
205-
{ resultSet: true, outFormat: oracledb.OBJECT },
206-
function(err, result) {
207-
should.not.exist(err);
208-
resultSet = result.resultSet;
209-
callback();
210-
}
211-
);
212-
},
213-
function verifyMetaData(callback) {
214-
should.exist(resultSet.metaData);
215-
var t = resultSet.metaData;
216-
t.should.eql( [ { name: 'NUM' }, { name: 'CONTENT' } ] );
217-
resultSet.close(callback);
218-
},
219-
function closeConn(callback) {
193+
it('52.8 can not call method, createLob()', function(done) {
194+
oracledb.getConnection(
195+
dbConfig,
196+
function(err, connection) {
197+
should.not.exist(err);
198+
220199
connection.release(function(err) {
221200
should.not.exist(err);
222-
callback();
201+
202+
connection.createLob(oracledb.CLOB, function(err, lob) {
203+
should.exist(err);
204+
should.not.exist(lob);
205+
should.strictEqual(
206+
err.message,
207+
"NJS-003: invalid connection"
208+
);
209+
done();
210+
});
223211
});
224-
},
225-
function getMetaData(callback) {
226-
should.strictEqual(resultSet.metaData, undefined);
227-
callback();
228-
},
229-
function getConn(callback) {
230-
oracledb.getConnection(
231-
dbConfig,
232-
function(err, conn) {
233-
should.not.exist(err);
234-
connection = conn;
235-
callback();
236-
}
237-
);
238-
},
239-
function dropTable(callback) {
240-
connection.execute(
241-
"DROP TABLE " + tableName + " PURGE",
242-
function(err) {
243-
should.not.exist(err);
244-
callback();
245-
}
246-
);
247-
},
248-
function closeConn(callback) {
212+
}
213+
);
214+
}); // 52.8
215+
216+
it('52.9 can not call method, queryStream()', function(done) {
217+
oracledb.getConnection(
218+
dbConfig,
219+
function(err, connection) {
220+
should.not.exist(err);
221+
222+
connection.release(function(err) {
223+
should.not.exist(err);
224+
225+
var stream = connection.queryStream("select sysdate from dual");
226+
should.exist(stream);
227+
228+
stream.on("data", function(data) {
229+
should.not.exist(data);
230+
});
231+
232+
stream.on("end", function() {
233+
done(new Error("should not emit 'end' event!"));
234+
});
235+
236+
stream.on("error", function(err) {
237+
should.exist(err);
238+
should.strictEqual(
239+
err.message,
240+
"NJS-003: invalid connection"
241+
);
242+
done();
243+
});
244+
});
245+
}
246+
);
247+
}); // 52.9
248+
249+
it('52.10 can not call release() multiple times', function(done) {
250+
oracledb.getConnection(
251+
dbConfig,
252+
function(err, connection) {
253+
should.not.exist(err);
254+
249255
connection.release(function(err) {
250256
should.not.exist(err);
251-
callback();
257+
258+
connection.release(function(err) {
259+
should.exist(err);
260+
should.strictEqual(
261+
err.message,
262+
"NJS-003: invalid connection"
263+
);
264+
done();
265+
});
252266
});
253-
},
254-
], done);
255-
});
267+
}
268+
);
269+
}); // 52.10
270+
271+
it('52.11 can not call method, rollback()', function(done) {
272+
oracledb.getConnection(
273+
dbConfig,
274+
function(err, connection) {
275+
should.not.exist(err);
276+
277+
connection.release(function(err) {
278+
should.not.exist(err);
279+
280+
connection.rollback(function(err) {
281+
should.exist(err);
282+
should.strictEqual(
283+
err.message,
284+
"NJS-003: invalid connection"
285+
);
286+
done();
287+
});
288+
});
289+
}
290+
);
291+
}); // 52.11
292+
293+
it("52.12 can access properties of closed connection without error", function(done) {
294+
oracledb.getConnection(
295+
dbConfig,
296+
function(err, connection) {
297+
should.not.exist(err);
298+
299+
connection.release(function(err) {
300+
should.not.exist(err);
301+
302+
should.strictEqual(connection.stmtCacheSize, undefined);
303+
should.strictEqual(connection.oracleServerVersion, undefined);
304+
should.strictEqual(connection.action, null);
305+
should.strictEqual(connection.clientId, null);
306+
should.strictEqual(connection.module, null);
307+
done();
308+
});
309+
}
310+
);
311+
}); // 52.12
256312

257-
});
313+
});

0 commit comments

Comments
 (0)