Search bug links in testrail only in N days before

For now there is over 200 requests in batch of 5 test runs iterating over all
created testplans, even older than half of year. Its absolutely not required
and testrail allow us to iterate through testplans created after date X.
We can use this feature and reduce time spent on useless get requests.

This patch introduces new variable TESTRAIL_DAYS_TO_ANALYZE that allow
us not to go too deep into testrail history. For now the default is 14 days.
It decreases uploading time from 20 minutes to 30-60 seconds and also reduces
load of testrail.

Change-Id: I468b14f6c5d6f8472b78980e3798f306068d3df2
(cherry picked from commit 2596c8d796)
This commit is contained in:
Vladimir Khlyunev 2017-01-27 15:50:21 +04:00
parent d7f19e75ed
commit d4bd269aae
3 changed files with 18 additions and 5 deletions

View File

@ -435,7 +435,8 @@ def publish_results(project, milestone_id, test_plan,
milestone_id=milestone_id,
suite_id=suite_id,
config_id=config_id,
limit=TestRailSettings.previous_results_depth)
limit=TestRailSettings.previous_results_depth,
days_to_analyze=TestRailSettings.previous_results_days_to_analyze)
logger.debug('Found next test runs: {0}'.format(
[test_run['description'] for test_run in previous_tests_runs]))
cases = project.get_cases(suite_id=suite_id)

View File

@ -74,6 +74,8 @@ class TestRailSettings(object):
tests_include = os.environ.get('TESTRAIL_TEST_INCLUDE', None)
tests_exclude = os.environ.get('TESTRAIL_TEST_EXCLUDE', None)
previous_results_depth = os.environ.get('TESTRAIL_TESTS_DEPTH', 5)
previous_results_days_to_analyze = os.environ.get(
'TESTRAIL_DAYS_TO_ANALYZE', 14)
operation_systems = []
centos_enabled = os.environ.get('USE_CENTOS', 'false') == 'true'
ubuntu_enabled = os.environ.get('USE_UBUNTU', 'true') == 'true'

View File

@ -14,6 +14,8 @@
from __future__ import unicode_literals
import time
from fuelweb_test.testrail.settings import logger
from fuelweb_test.testrail.testrail import APIClient
from fuelweb_test.testrail.testrail import APIError
@ -182,7 +184,8 @@ class TestRailProject(object):
def get_case_fields(self):
return self.client.send_get('get_case_fields')
def get_plans(self, milestone_ids=None, limit=None, offset=None):
def get_plans(self, milestone_ids=None, limit=None, offset=None,
created_after=None):
plans_uri = 'get_plans/{project_id}'.format(
project_id=self.project['id'])
if milestone_ids:
@ -192,6 +195,9 @@ class TestRailProject(object):
plans_uri += '&limit={0}'.format(limit)
if offset:
plans_uri += '&offset={0}'.format(offset)
if created_after:
plans_uri += '&created_after={0}'.format(created_after)
return self.client.send_get(plans_uri)
def get_plan(self, plan_id):
@ -260,14 +266,18 @@ class TestRailProject(object):
if run['name'] == name:
return self.get_run(run_id=run['id'])
def get_previous_runs(self, milestone_id, suite_id, config_id, limit=None):
def get_previous_runs(self, milestone_id, suite_id, config_id, limit=None,
days_to_analyze=None):
previous_runs = []
offset = 0
current_time = int(time.time())
day_in_seconds = 24 * 60 * 60
created_after = current_time - (day_in_seconds * days_to_analyze)
while len(previous_runs) < limit:
existing_plans = self.get_plans(milestone_ids=[milestone_id],
limit=limit,
offset=offset)
offset=offset,
created_after=created_after)
if not existing_plans:
break