Skip to content

Commit 01919b1

Browse files
committed
Add some negative tests of CQN unsubscription
1 parent 09c6849 commit 01919b1

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

test/list.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,6 +4406,9 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
44064406
185.4 Negative - provide invalid SQL in CQN option
44074407
185.5 examples/cqn2.js
44084408
185.6 getting registration ID "regId" for subscriptions
4409+
185.7 Negative - unsubscribe multiple times
4410+
185.8 Negative - unsubscribe nonexistent subscriptions
4411+
185.9 Negative - unsubscribe the subscription which throwed error when subscribed
44094412

44104413
186. instanceof2.js
44114414
186.1 instanceof checks for SODA classes

test/runCQN.js

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ describe('185. runCQN.js', function() {
241241

242242
it('185.4 Negative - provide invalid SQL in CQN option', async() => {
243243
try {
244-
245244
const TABLE = 'nodb_tab_cqn_4';
246245
const myCallback = async function(message) {
247246
console.log(message);
@@ -369,4 +368,99 @@ describe('185. runCQN.js', function() {
369368
}
370369
}); // 185.6
371370

371+
it('185.7 Negative - unsubscribe multiple times', async () => {
372+
try {
373+
const TABLE = 'nodb_tab_cqn_7';
374+
let sql =
375+
`CREATE TABLE ${TABLE} (
376+
k NUMBER
377+
)`;
378+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
379+
await conn.execute(plsql);
380+
381+
const myCallback = async function(message) {
382+
// console.log(message);
383+
should.strictEqual(message.registered, true);
384+
};
385+
386+
const options = {
387+
callback : myCallback,
388+
sql: `SELECT * FROM ${TABLE} WHERE k > :bv`,
389+
binds: { bv : 100 },
390+
timeout : 20,
391+
qos : oracledb.SUBSCR_QOS_QUERY | oracledb.SUBSCR_QOS_ROWIDS
392+
};
393+
394+
await conn.subscribe('sub7', options);
395+
396+
sql = `INSERT INTO ${TABLE} VALUES (101)`;
397+
await conn.execute(sql);
398+
399+
plsql = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
400+
await conn.execute(plsql);
401+
await conn.commit();
402+
403+
await conn.unsubscribe('sub7');
404+
405+
sql = `DROP TABLE ${TABLE} PURGE`;
406+
await conn.execute(sql);
407+
408+
await assert.rejects(
409+
async () => {
410+
await conn.unsubscribe('sub7');
411+
},
412+
/NJS-061/
413+
);
414+
// NJS-061: invalid subscription
415+
} catch (err) {
416+
should.not.exist(err);
417+
}
418+
419+
}); // 185.7
420+
421+
it('185.8 Negative - unsubscribe nonexistent subscriptions', async () => {
422+
try {
423+
await assert.rejects(
424+
async () => {
425+
await conn.unsubscribe('nonexist');
426+
},
427+
/NJS-061/
428+
);
429+
// NJS-061: invalid subscription
430+
} catch (err) {
431+
should.not.exist(err);
432+
}
433+
}); // 185.8
434+
435+
// An variation of 185.4
436+
it('185.9 Negative - unsubscribe the subscription which throwed error when subscribed', async () => {
437+
try {
438+
const TABLE = 'nodb_tab_cqn_9';
439+
const myCallback = async function(message) {
440+
console.log(message);
441+
};
442+
443+
const options = {
444+
callback : myCallback,
445+
sql: `DELETE FROM ${TABLE} WHERE k > :bv`,
446+
binds: { bv : 100 },
447+
timeout : 20,
448+
qos : oracledb.SUBSCR_QOS_QUERY
449+
};
450+
451+
await assert.rejects(
452+
async () => {
453+
await conn.subscribe('sub9', options);
454+
},
455+
/DPI-1013/
456+
);
457+
// DPI-1013: not supported
458+
459+
conn.unsubscribe('sub9');
460+
461+
} catch (err) {
462+
should.not.exist(err);
463+
}
464+
}); // 185.9
465+
372466
});

0 commit comments

Comments
 (0)