Skip to content

Commit

Permalink
Merge pull request #127 from direvius/master
Browse files Browse the repository at this point in the history
start IOloop, render offline report
  • Loading branch information
direvius committed Dec 29, 2014
2 parents 5872d68 + c25670d commit 68d2618
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Tank/Plugins/OnlineReport/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ def start_test(self):


def end_test(self, retcode):
self.log.info("Ended test. Sending command to reload pages.")
self.server.reload()
return retcode


def run(self):
if (self.server):
address = socket.gethostname()
self.log.info("Starting local HTTP server for online view at port: http://%s:%s/", address, self.port)
self.server.serve()
self.server.reload()
self.log.info("Server started.")


def aggregate_second(self, data):
Expand All @@ -100,10 +99,11 @@ def post_process(self, retcode):
self.log.info("Building HTML report...")
report_html = self.core.mkstemp(".html", "report_")
self.core.add_artifact_file(report_html)
#with open(report_html, 'w') as report_html_file:
# report_html_file.write(
# requests.get('http://localhost:8001/offline.html').text
# )
with open(report_html, 'w') as report_html_file:
report_html_file.write(
#requests.get('http://localhost:8001/offline.html').text
self.server.render_offline()
)
#raw_input('Press Enter to stop report server.')
self.server.stop()
del self.server
Expand Down
11 changes: 10 additions & 1 deletion Tank/Plugins/OnlineReport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def get(self):
class ReportServer(object):
def __init__(self, cacher):
router = TornadioRouter(Client)
self.cacher = cacher
self.reportUUID = uuid.uuid4().hex
self.app = tornado.web.Application(
router.apply_routes([
Expand All @@ -92,7 +93,7 @@ def __init__(self, cacher):

def serve(self):
def run_server(server):
server.start()
tornado.ioloop.IOLoop.instance().start()

self.server = SocketServer(self.app, auto_start = False)
th = Thread(target=run_server, args=(self.server,))
Expand All @@ -109,3 +110,11 @@ def send(self, data):
def reload(self):
for connection in Client.CONNECTIONS:
connection.emit('reload')

def render_offline(self):
loader = template.Loader(os.path.join(os.path.dirname(__file__), "templates"))
cached_data = {
'data': self.cacher.get_all_data(),
'uuid': self.reportUUID,
}
return loader.load('offline.jade').generate(cached_data=json.dumps(cached_data))

0 comments on commit 68d2618

Please sign in to comment.