Skip to content

Commit

Permalink
Add Flag for reuse session in LH
Browse files Browse the repository at this point in the history
  • Loading branch information
imkalvin committed Jul 13, 2021
1 parent 0f90a0a commit b63a7d8
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions wptagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ def __init__(self, options, browsers):
self.image_magick['mogrify'] = mogrify
break

def reuse_session_in_lighthouse(self):
return len(self.task['script']) > 0

def launch_browser(self):
self.browser = self.browsers.get_browser(self.job['browser'], self.job)
if self.browser is not None:
self.browser.prepare(self.job, self.task)
self.browser.launch(self.job, self.task)

def stop_browser(self):
if self.browser is not None:
self.browser.stop(self.job, self.task)
# Delete the browser profile if needed
if self.task['cached'] or self.job['fvonly']:
self.browser.clear_profile(self.task)
self.browser = None

def run_testing(self):
"""Main testing flow"""
if (sys.version_info >= (3, 0)):
Expand Down Expand Up @@ -143,13 +160,12 @@ def run_testing(self):
while self.task is not None:
start = monotonic()

self.task['running_lighthouse'] = False
self.browser = self.browsers.get_browser(self.job['browser'], self.job)
if self.browser is not None:
self.browser.prepare(self.job, self.task)
self.browser.launch(self.job, self.task)

try:
self.task['running_lighthouse'] = False
self.task['reuse_session_in_lighthouse'] = self.reuse_session_in_lighthouse()
if self.task['reuse_session_in_lighthouse']:
self.launch_browser()

if self.job['type'] != 'lighthouse':
self.run_single_test()
self.wpt.get_bodies(self.task)
Expand All @@ -162,8 +178,18 @@ def run_testing(self):
self.task['page_result'] == 0 or \
self.task['page_result'] == 99999:
self.task['running_lighthouse'] = True

if not self.task['reuse_session_in_lighthouse']:
self.wpt.running_another_test(self.task)

self.run_single_test()
self.wpt.running_another_test(self.task)

if self.task['reuse_session_in_lighthouse']:
self.wpt.running_another_test(self.task)

if self.task['reuse_session_in_lighthouse']:
self.stop_browser()

elapsed = monotonic() - start
logging.debug('Test run time: %0.3f sec', elapsed)
except Exception as err:
Expand All @@ -176,13 +202,6 @@ def run_testing(self):
traceback.print_exc(file=sys.stdout)
self.wpt.upload_task_result(self.task)

if self.browser is not None:
self.browser.stop(self.job, self.task)
# Delete the browser profile if needed
if self.task['cached'] or self.job['fvonly']:
self.browser.clear_profile(self.task)
self.browser = None

# Set up for the next run
self.task = self.wpt.get_task(self.job)
elif self.options.exit > 0 and self.browsers.should_exit():
Expand Down Expand Up @@ -221,6 +240,10 @@ def run_single_test(self):
if self.health_check_server is not None:
self.health_check_server.healthy()
self.alive()

if not self.task['reuse_session_in_lighthouse']:
self.launch_browser()

if self.browser is not None:
try:
if self.task['running_lighthouse']:
Expand Down Expand Up @@ -251,6 +274,8 @@ def run_single_test(self):
logging.critical(err)
self.task['error'] = err

if not self.task['reuse_session_in_lighthouse']:
self.stop_browser()

def signal_handler(self, signum, frame):
"""Ctrl+C handler"""
Expand Down

0 comments on commit b63a7d8

Please sign in to comment.