summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2015-04-13 12:31:46 +0000
committerNanang Izzuddin <nanang@teluu.com>2015-04-13 12:31:46 +0000
commit5cf8c9ffea5a36635ff29fe05392d3fd1a690fb2 (patch)
tree2a39c54e4f2e5e043d882f96d24db5ca53764403 /tests
parenta37a581a5e1f22027081f41891f2bf9ca88d5998 (diff)
Re #1842: Minor update on python test to reduce possibility of EADDRINUSE error in running pjsua.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5068 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'tests')
-rw-r--r--tests/pjsua/inc_cfg.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/pjsua/inc_cfg.py b/tests/pjsua/inc_cfg.py
index d75c17f3..2345d8f2 100644
--- a/tests/pjsua/inc_cfg.py
+++ b/tests/pjsua/inc_cfg.py
@@ -1,6 +1,8 @@
# $Id$
import random
import config_site
+import socket
+import errno
DEFAULT_ECHO = True
DEFAULT_TRACE = True
@@ -46,7 +48,22 @@ class InstanceParam:
self.name = name
# Give random sip_port if it's not specified
if sip_port==0:
- self.sip_port = random.randint(DEFAULT_START_SIP_PORT, 65534)
+ # avoid port conflict
+ cnt = 0
+ port = 0
+ while cnt < 10:
+ cnt = cnt + 1
+ port = random.randint(DEFAULT_START_SIP_PORT, 65534)
+ s = socket.socket(socket.AF_INET)
+ try:
+ s.bind(("0.0.0.0", port))
+ except socket.error as serr:
+ s.close()
+ if serr.errno == errno.EADDRINUSE:
+ continue
+ s.close()
+ break;
+ self.sip_port = port
else:
self.sip_port = sip_port
# Autogenerate URI if it's empty.