Skip to content

Ensure session reported end on "slash.app_quit" hook (closes #82) #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion backslash/contrib/slash_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
_HAS_TEST_AVOIDED = (int(slash.__version__.split('.')[0]) >= 1)
_HAS_SESSION_INTERRUPT = hasattr(slash.hooks, 'session_interrupt')
_HAS_TEST_DISTRIBUTED = hasattr(slash.hooks, 'test_distributed')
_HAS_APP_QUIT = hasattr(slash.hooks, 'app_quit')

def handle_exceptions(func):

Expand Down Expand Up @@ -76,6 +77,7 @@ def __init__(self, url=None, keepalive_interval=None, runtoken=None,
self._error_containers = {}
self._runtoken = runtoken
self._propagate_exceptions = propagate_exceptions
self._started = False

@property
def rest_url(self):
Expand Down Expand Up @@ -158,6 +160,7 @@ def _notify_session_start(self):
metadata=metadata,
**self._get_extra_session_start_kwargs()
)
self._started = True
for warning in slash.context.session.warnings:
self.warning_added(warning)
for label in self.current_config.session_labels:
Expand Down Expand Up @@ -277,6 +280,7 @@ def test_distributed(self, test_logical_id, worker_session_id): #pylint: disable
if 'report_test_distributed' in self.client.api.info().endpoints:
self.current_test = self.session.report_test_distributed(test_logical_id)


@handle_exceptions
def test_skip(self, reason=None):
self.current_test.mark_skipped(reason=reason)
Expand Down Expand Up @@ -409,6 +413,16 @@ def test_end(self):

@handle_exceptions
def session_end(self):
self._session_report_end('session_end')

@slash.plugins.register_if(_HAS_APP_QUIT)
@handle_exceptions # pylint: disable=unused-argument
def app_quit(self):
self._session_report_end('app_quit')

def _session_report_end(self, hook_name):
if not self._started:
return
try:
if self._keepalive_thread is not None:
self._keepalive_thread.stop()
Expand All @@ -419,8 +433,9 @@ def session_end(self):
if self.client.api.info().endpoints.report_session_end.version >= 2:
kwargs['has_fatal_errors'] = has_fatal_errors
self.session.report_end(**kwargs)
self._started = False
except Exception: # pylint: disable=broad-except
_logger.error('Exception ignored in session_end', exc_info=True)
_logger.error('Exception ignored in {}'.format(hook_name), exc_info=True)

@handle_exceptions
def error_added(self, result, error):
Expand Down