From b5f9820f317152298c3a15f29102d7b82ac0821b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 30 Nov 2017 01:20:45 -0500 Subject: [PATCH] Add a dialplan timeout test Verify that when a session is parked but not handled within the timeout period (in this case 3 seconds as set in our CI dialplan) it is cancelled by FS. In the contrary case verify that a simple `session.answer()` within the timeout results in a successful SIPp `uac` client scenario. Resolves #47 --- conf/ci-minimal/dialplan/switchydp.xml | 4 +-- tests/test_coroutines.py | 48 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/conf/ci-minimal/dialplan/switchydp.xml b/conf/ci-minimal/dialplan/switchydp.xml index e082009..4525e27 100644 --- a/conf/ci-minimal/dialplan/switchydp.xml +++ b/conf/ci-minimal/dialplan/switchydp.xml @@ -1,10 +1,10 @@ - - + + diff --git a/tests/test_coroutines.py b/tests/test_coroutines.py index 966e4b6..92630f9 100644 --- a/tests/test_coroutines.py +++ b/tests/test_coroutines.py @@ -88,3 +88,51 @@ async def timeout_on_hangup(self, sess): assert task.done() with pytest.raises(asyncio.TimeoutError): task.result() + + +@pytest.mark.parametrize('sleep', [2, 5]) +def test_simplest_flow(fssock, scenario, client, ael, sleep): + """Verify that a coroutine can satisfy SIPp's simplest call flow. + + Additionally, verify that when calls are not answered and left in the park + state they time out and are rejected after 3 seconds (according to the CI + dialplan). + """ + class MyApp: + @coroutine( + "CHANNEL_PARK", + subscribe=('PLAYBACK_STOP', 'PLAYBACK_START') + ) + async def answer_play_hangup(self, sess): + await asyncio.sleep(sleep) + await sess.answer() + # non-blocking + sess.playback( + 'en/us/callie/ivr/8000/ivr-founder_of_freesource.wav') + await sess.recv("PLAYBACK_START") + await sess.recv("CHANNEL_HANGUP") + # XXX: seems the playback isn't stopping on its own? - the + # hangup does it though... + # sess.breakmedia() + await sess.recv("PLAYBACK_STOP") + await sess.recv("CHANNEL_HANGUP_COMPLETE") + + client.connect() + client.listener = ael + # assigning a listener overrides it's call lookup var so restore it + client.listener.call_tracking_header = 'variable_call_uuid' + assert 'default' == client.load_app(MyApp, on_value="default") + + uac = scenario.prepare()[1] + uac.proxyaddr = None + uac.destaddr = fssock + uac.pause_duration = 6000 + + # make the call + if sleep > 3: + # XML dialplan's `park_timeout` should reject the call + with pytest.raises(RuntimeError): + uac() + else: + # call should be hung up by this UAC + uac()