Skip to content

Commit c16971e

Browse files
author
Bill Prin
committed
DHermes review
1 parent 89dba86 commit c16971e

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

error_reporting/google/cloud/error_reporting/_gax.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from google.cloud.gapic.errorreporting.v1beta1 import (
2121
report_errors_service_client)
22+
2223
from google.cloud.proto.devtools.clouderrorreporting.v1beta1 import (
2324
report_errors_service_pb2)
2425
from google.protobuf.json_format import ParseDict

error_reporting/google/cloud/error_reporting/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class HTTPContext(object):
6060
the IP address, depending on the data that has been
6161
provided in the error report.
6262
"""
63-
6463
def __init__(self, method=None, url=None,
6564
user_agent=None, referrer=None,
6665
response_status_code=None, remote_ip=None):
@@ -124,7 +123,7 @@ class Client(ClientWithProject):
124123
"""
125124

126125
SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)
127-
"""The scopes required for authenticating as an API consumer."""
126+
"""The scopes required for authenticating as an Error Reporting consumer."""
128127

129128
def __init__(self, project=None,
130129
credentials=None,

error_reporting/tests/system.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import functools
15+
import time
1616
import unittest
1717

1818
from google.cloud import error_reporting
@@ -22,75 +22,73 @@
2222
error_stats_service_pb2)
2323
from google.protobuf.duration_pb2 import Duration
2424

25-
from test_utils.retry import RetryResult
2625

26+
def setUpModule():
27+
Config.CLIENT = error_reporting.Client()
2728

28-
class _ErrorStatsGaxApi(object):
29-
"""Helper mapping Error Reporting-related APIs
3029

31-
This class provides a small wrapper around making calls to the GAX
30+
class Config(object):
31+
"""Run-time configuration to be modified at set-up.
32+
33+
This is a mutable stand-in to allow test set-up to modify
34+
global state.
35+
"""
36+
CLIENT = None
37+
38+
39+
def _list_groups(project):
40+
"""List Error Groups from the last 60 seconds.
41+
42+
This class provides a wrapper around making calls to the GAX
3243
API. It's used by the system tests to find the appropriate error group
3344
to verify the error was successfully reported.
3445
3546
:type project: str
3647
:param project: Google Cloud Project ID
3748
"""
38-
def __init__(self, project):
39-
self._project = project
40-
self._gax_api = error_stats_service_client.ErrorStatsServiceClient()
41-
42-
def list_groups(self):
43-
"""Helper to list the groups that have had errors in the last hour."""
44-
project_name = self._gax_api.project_path(self._project)
45-
time_range = error_stats_service_pb2.QueryTimeRange()
46-
time_range.period = (
47-
error_stats_service_pb2.QueryTimeRange.PERIOD_1_HOUR
48-
)
49+
gax_api = error_stats_service_client.ErrorStatsServiceClient()
50+
project_name = gax_api.project_path(project)
4951

50-
duration = Duration()
51-
duration.seconds = 60 * 60
52+
time_range = error_stats_service_pb2.QueryTimeRange()
53+
time_range.period = (
54+
error_stats_service_pb2.QueryTimeRange.PERIOD_1_HOUR
55+
)
5256

53-
return self._gax_api.list_group_stats(
54-
project_name, time_range, timed_count_duration=duration)
57+
duration = Duration()
58+
duration.seconds = 60 * 60
5559

60+
return gax_api.list_group_stats(
61+
project_name, time_range, timed_count_duration=duration)
5662

57-
def _is_incremented(initial, new):
58-
"""Helper to retry until new error is counted."""
59-
return new == initial + 1
63+
ERROR_NAME = 'Stackdriver Error Reporting System Test'
6064

6165

6266
class TestErrorReporting(unittest.TestCase):
6367

64-
def setUp(self):
65-
self._client = error_reporting.Client()
66-
self._error_name = 'Stackdriver Error Reporting System Test'
67-
6868
def _simulate_exception(self):
6969
"""Simulates an exception to verify it was reported."""
7070
try:
71-
raise RuntimeError(self._error_name)
71+
raise RuntimeError(ERROR_NAME)
7272
except RuntimeError:
73-
self._client.report_exception()
73+
Config.CLIENT.report_exception()
7474

7575
def _get_error_count(self):
7676
"""Counts the number of errors in the group of the test exception."""
77-
error_stats_api = _ErrorStatsGaxApi(self._client.project)
78-
groups = error_stats_api.list_groups()
77+
groups = _list_groups(Config.CLIENT.project)
7978
for group in groups:
80-
if self._error_name in group.representative.message:
79+
if ERROR_NAME in group.representative.message:
8180
return group.count
8281

8382
def test_report_exception(self):
84-
"""Verifies the exception reported increases the group count by one."""
8583
# If test has never run, group won't exist until we report first
8684
# exception, so first simulate it just to create the group
8785
self._simulate_exception()
86+
time.sleep(2)
8887

8988
initial_count = self._get_error_count()
9089
self._simulate_exception()
9190

92-
is_incremented = functools.partial(_is_incremented, initial_count)
93-
retry_get_count = RetryResult(is_incremented)(self._get_error_count)
94-
new_count = retry_get_count()
91+
time.sleep(2)
92+
new_count = self._get_error_count()
9593

9694
self.assertEqual(new_count, initial_count + 1)

0 commit comments

Comments
 (0)