add sip decline testcase

This commit is contained in:
Quan HL
2023-07-27 11:52:38 +07:00
parent 2b4fc478b0
commit cf8d47cb94
3 changed files with 63 additions and 7 deletions

View File

@@ -796,9 +796,9 @@ class CallSession extends Emitter {
}
}
if (0 === this.tasks.length && ((this.requestor instanceof WsRequestor && !this.callGone) ||
// Tasks are all done, but dialog is not establish yet, waiting for cancel/handup the call.
!this.dlg)) {
if (0 === this.tasks.length && ((this.requestor instanceof WsRequestor && !this.callGone)||
// Tasks are all done, but outgoing dialog is not establish yet, waiting for cancel/handup the call.
!this.dlg && !this.isFinalStatus() && this.direction === CallDirection.Outbound)) {
//let span;
try {
//const {span} = this.rootSpan.startChildSpan('waiting for commands');
@@ -1793,16 +1793,15 @@ class CallSession extends Emitter {
this.updateCallStatus(Object.assign({}, this.callInfo.toJSON()), this.serviceUrl)
.catch((err) => this.logger.error(err, 'redis error'));
if (this.wakeupResolver && !this.dlg && this.isCurrentCallStatusHigherThan(CallStatus.Failed)) {
if (this.wakeupResolver && !this.dlg && this.isFinalStatus()) {
// Someone is waiting for call to be final
this.wakeupResolver({reason: 'session ended'});
this.wakeupResolver = null;
}
}
isCurrentCallStatusHigherThan(target) {
const obj = Object.values(CallStatus);
return obj.indexOf(this.callStatus) >= obj.indexOf(target);
isFinalStatus() {
return [CallStatus.Failed, CallStatus.Busy, CallStatus.NoAnswer, CallStatus.Completed].includes(this.callStatus)
}
async executeStatusCallback(callStatus, sipStatus) {

View File

@@ -15,5 +15,6 @@ require('./sip-refer-tests');
require('./listen-tests');
require('./config-test');
require('./queue-test');
require('./sip-decline-test');
require('./remove-test-db');
require('./docker_stop');

56
test/sip-decline-test.js Normal file
View File

@@ -0,0 +1,56 @@
const test = require('tape');
const { sippUac } = require('./sipp')('test_fs');
const clearModule = require('clear-module');
const {provisionCallHook} = require('./utils');
const bent = require('bent');
const getJSON = bent('json');
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
function connect(connectable) {
return new Promise((resolve, reject) => {
connectable.on('connect', () => {
return resolve();
});
});
}
test('\'sip:decline\' tests', async(t) => {
clearModule.all();
const {srf, disconnect} = require('../app');
try {
await connect(srf);
// GIVEN
const verbs = [
{
"verb": "sip:decline",
"status": 480,
"reason": "Gone Fishing",
"headers" : {
"Retry-After": 1800
}
}
];
const from = 'sip_delecine_success';
await provisionCallHook(from, verbs)
// THEN
await sippUac('uac-invite-expect-480.xml', '172.38.0.10', from);
let obj = await getJSON(`http:127.0.0.1:3100/requests/${from}_callStatus`);
t.ok(obj.map((o) => o.body.call_status).includes('failed'),
'sip:decline: status callback successfully executed');
disconnect();
} catch (err) {
console.log(`error received: ${err}`);
disconnect();
t.error(err);
}
});