Skip to content
Permalink
Browse files

Add timeout to GetMap for local test server

  • Loading branch information
dakcarto committed Feb 21, 2014
1 parent 722ae6e commit 7afede9bc9e7186f9d6371d358a72c3d438805ca
Showing with 58 additions and 14 deletions.
  1. +58 −14 tests/src/python/qgis_local_server.py
@@ -189,7 +189,9 @@ def __init__(self, kind, exe, fcgi_bin, conf_dir, temp_dir):
fcgi_sock = os.path.join(temp_dir, 'var', 'run',
'qgs_mapserv.sock')
if self._mac:
self.set_startenv({'QGIS_LOG_FILE': '{0}/log/qgis_server.log'.format(temp_dir)})
self.set_startenv({
'QGIS_LOG_FILE':
'{0}/log/qgis_server.log'.format(temp_dir)})
init_scr = os.path.join(conf_dir, 'fcgi', 'scripts',
'spawn_fcgi_mac.sh')
self.set_startcmd([init_scr, 'start', exe, fcgi_sock,
@@ -450,19 +452,61 @@ def get_map(self, params, browser=False):
openInBrowserTab(url)
return False, ''

tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
success = True
filepath = tmp.name
# print 'filepath: ' + filepath
tmp.close()
filepath2, headers = urllib.urlretrieve(url, tmp.name)

if (headers.getmaintype() != 'image' or
headers.getheader('Content-Type') != 'image/png'):
success = False
if os.path.exists(filepath):
os.unlink(filepath)
filepath = ''
# try until qgis_mapserv.fcgi process is available (for 20 seconds)
# on some platforms the fcgi_server_process is a daemon handling the
# launch of the fcgi-spawner, which may be running quickly, but the
# qgis_mapserv.fcgi spawned process is not yet accepting connections
resp = None
tmp_png = None
# noinspection PyUnusedLocal
filepath = ''
# noinspection PyUnusedLocal
success = False
start_time = time.time()
while time.time() - start_time < 20:
resp = None
try:
tmp_png = urllib2.urlopen(url)
except urllib2.HTTPError as resp:
if resp.code == 503 or resp.code == 500:
time.sleep(1)
else:
raise ServerProcessError(
'Web/FCGI Process Request HTTPError',
'Cound not connect to process: ' + str(resp.code),
resp.message
)
except urllib2.URLError as resp:
raise ServerProcessError(
'Web/FCGI Process Request URLError',
'Cound not connect to process: ' + str(resp.code),
resp.reason
)
else:
delta = time.time() - start_time
print 'Seconds elapsed for server GetMap: ' + str(delta)
break

if resp is not None:
raise ServerProcessError(
'Web/FCGI Process Request Error',
'Cound not connect to process: ' + str(resp.code)
)

if (tmp_png is not None
and tmp_png.info().getmaintype() == 'image'
and tmp_png.info().getheader('Content-Type') == 'image/png'):

tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
filepath = tmp.name
tmp.write(tmp_png.read())
tmp.close()
success = True
else:
raise ServerProcessError(
'FCGI Process Request Error',
'No valid PNG output'
)

return success, filepath

0 comments on commit 7afede9

Please sign in to comment.
You can’t perform that action at this time.