Skip to content

Commit

Permalink
[feat] Silence API errors while streaming results by default, with op…
Browse files Browse the repository at this point in the history
…tion not to
  • Loading branch information
robingustafsson committed Feb 14, 2018
1 parent 700beb7 commit a829938
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions loadimpact3/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import json

from .exceptions import CoercionError, ResponseParseError
from .exceptions import CoercionError, ResponseParseError, ServerError
from .fields import (
DataStoreListField, DateTimeField, DictField, Field, IntegerField,
UnicodeField, BooleanField, ListField, TimeStampField, FloatField)
Expand Down Expand Up @@ -357,9 +357,10 @@ def start_test_run(self):


class _TestRunResultStream(object):
def __init__(self, test_run, result_ids):
def __init__(self, test_run, result_ids, raise_api_errors=False):
self.test_run = test_run
self.result_ids = result_ids
self.raise_api_errors = raise_api_errors
self._last = dict([(rid, {'offset': -1, 'data': {}}) for rid in result_ids])
self._last_two = []
self._series = {}
Expand Down Expand Up @@ -391,7 +392,12 @@ def is_done(self):
q = ['%s|%d' % (rid, self._last.get(rid, {}).get('offset', -1))
for rid in self.result_ids]

results = TestRunResults.list(self.test_run.client, self.test_run.id, {'ids': ','.join(q)})
try:
results = TestRunResults.list(self.test_run.client, self.test_run.id, {'ids': ','.join(q)})
except ServerError as e:
if self.raise_api_errors:
raise e
results = []
change = {}
for result in results:
try:
Expand Down Expand Up @@ -460,7 +466,7 @@ class TestRun(Resource, ListMixin, GetMixin, CreateMixin, DeleteMixin):
def list_test_run_result_ids(self, data):
return self.client.list_test_run_result_ids(self.id, data)

def result_stream(self, result_ids=None):
def result_stream(self, result_ids=None, raise_api_errors=False):
"""Get access to result stream.
Args:
result_ids: List of result IDs to include in this stream.
Expand All @@ -476,7 +482,7 @@ def result_stream(self, result_ids=None):
TestRunMetric.result_id_from_name(TestRunMetric.USER_LOAD_TIME, load_zone_id),
TestRunMetric.result_id_from_name(TestRunMetric.FAILURE_RATE, load_zone_id)
]
return self.__class__.stream_class(self, result_ids)
return self.__class__.stream_class(self, result_ids, raise_api_errors=raise_api_errors)

def is_done(self):
"""Check whether test is done or not.
Expand Down

0 comments on commit a829938

Please sign in to comment.