forked from organicmaps/organicmaps
Merge pull request #32 from mapsmetest/testing_fix_tornado_2
Fixed the tornado server for Downloader tests
This commit is contained in:
commit
25efce3c27
4 changed files with 22 additions and 33 deletions
|
@ -1,5 +1,7 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
BIG_FILE_SIZE = 47684
|
||||
|
||||
|
@ -193,5 +195,6 @@ class ResponseProvider:
|
|||
|
||||
|
||||
def kill(self):
|
||||
logging.debug("Kill called in ResponseProvider")
|
||||
self.delegate.kill()
|
||||
return Payload("Bye...")
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
import logging
|
||||
|
||||
import os
|
||||
import re
|
||||
import urllib2
|
||||
import socket
|
||||
from subprocess import Popen, PIPE
|
||||
from time import sleep
|
||||
|
||||
import logging
|
||||
|
||||
|
@ -22,7 +25,10 @@ class SiblingKiller:
|
|||
def allow_serving(self):
|
||||
return self.__allow_serving
|
||||
|
||||
def give_process_time_to_kill_port_user(self):
|
||||
sleep(5)
|
||||
|
||||
|
||||
def kill_siblings(self):
|
||||
"""
|
||||
The idea is to get the list of all processes by the current user, check which one of them is using the port.
|
||||
|
@ -33,15 +39,13 @@ class SiblingKiller:
|
|||
|
||||
If we are the process with the same name as ours and with the lowest process id, let's start serving and kill everyone else.
|
||||
"""
|
||||
self.kill_process_on_port() # changes __allow_serving to True if the process was alive and serving
|
||||
|
||||
sibs = self.siblings()
|
||||
|
||||
if self.__allow_serving:
|
||||
self.kill(pids=sibs)
|
||||
return
|
||||
|
||||
for sibling in sibs:
|
||||
logging.debug("Checking whether we should kill sibling id: {}".format(sibling))
|
||||
|
||||
self.give_process_time_to_kill_port_user()
|
||||
|
||||
if self.wait_for_server():
|
||||
serving_pid = self.serving_process_id()
|
||||
if serving_pid:
|
||||
|
@ -50,6 +54,9 @@ class SiblingKiller:
|
|||
return
|
||||
else:
|
||||
self.kill(pid=sibling)
|
||||
|
||||
self.kill_process_on_port() # changes __allow_serving to True if the process was alive and serving
|
||||
|
||||
|
||||
|
||||
def kill(self, pid=0, pids=list()):
|
||||
|
|
|
@ -53,31 +53,7 @@ except:
|
|||
USE_TORNADO = False
|
||||
|
||||
|
||||
dict = {
|
||||
'version': 1,
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class" : "logging.StreamHandler",
|
||||
"formatter": "default",
|
||||
"level" : "DEBUG",
|
||||
# "stream" : "ext://sys.stdout"
|
||||
}
|
||||
},
|
||||
|
||||
"formatters": {
|
||||
"default":{
|
||||
"format": '%(asctime)s %(levelname)-8s %(name)-15s %(message)s',
|
||||
"datefmt": '%Y-%m-%d %H:%M:%S'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# logging.config.dictConfig(dict)
|
||||
|
||||
|
||||
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
|
||||
logging.warning('is when this event was logged.')
|
||||
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
|
||||
|
||||
PORT = 34568
|
||||
LIFESPAN = 180.0 # timeout for the self destruction timer - how much time
|
||||
|
@ -228,6 +204,7 @@ class PostHandler(BaseHTTPRequestHandler, ResponseProviderMixin):
|
|||
|
||||
|
||||
def kill(self):
|
||||
logging.debug("Kill called in testserver")
|
||||
self.server.suicide()
|
||||
|
||||
|
||||
|
|
|
@ -71,8 +71,10 @@ class MainHandler(tornado.web.RequestHandler, ResponseProviderMixin):
|
|||
@staticmethod
|
||||
def reset_self_destruct_timer():
|
||||
if MainHandler.self_destruct_timer:
|
||||
logging.debug("Canceling the kill timer")
|
||||
MainHandler.self_destruct_timer.cancel()
|
||||
MainHandler.self_destruct_timer = Timer(MainHandler.lifespan, MainHandler.suicide())
|
||||
MainHandler.self_destruct_timer = Timer(MainHandler.lifespan, MainHandler.suicide)
|
||||
logging.debug("Starting the kill timer")
|
||||
MainHandler.self_destruct_timer.start()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue