Skip to content
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

backport tests: consolidate marathon purge fixture #3856 #3858

Merged
merged 1 commit into from Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 23 additions & 8 deletions packages/dcos-integration-test/extra/conftest.py
Expand Up @@ -2,6 +2,7 @@
import os

import pytest
import requests
from test_dcos_diagnostics import (
_get_bundle_list,
check_json,
Expand Down Expand Up @@ -66,19 +67,33 @@ def pytest_collection_modifyitems(session, config, items):
items[:] = new_items + last_items


# Note(JP): Attempt to reset Marathon state before and after every
# test run in this test suite. This is a brute force approach but
# we found that the problem of side effects as of too careless
# test isolation and resource cleanup became too large.
# Note(JP): Attempt to reset Marathon state before and after every test run in
# this test suite. This is a brute force approach but we found that the problem
# of side effects as of too careless test isolation and resource cleanup became
# too large. If this test suite ever introduces a session- or module-scoped
# fixture providing a Marathon app then the `autouse=True` approach will need to
# be relaxed.
@pytest.fixture(autouse=True)
def clean_marathon_state(dcos_api_session):
dcos_api_session.marathon.purge()
"""
Attempt to clean up Marathon state before entering the test and when leaving
the test. Especially attempt to clean up when the test code failed. When the
cleanup fails do not fail the test but log relevant information.
"""

def _purge_nofail():
try:
dcos_api_session.marathon.purge()
except Exception as exc:
log.exception('Ignoring exception during marathon.purge(): %s', exc)
if isinstance(exc, requests.exceptions.HTTPError):
log.error('exc.response.text: %s', exc.response.text)

_purge_nofail()
try:
yield
finally:
# This is in `finally:` so that we attempt to clean up
# Marathon state especially when the test code failed.
dcos_api_session.marathon.purge()
_purge_nofail()


@pytest.fixture(scope='session')
Expand Down