Skip to content

Commit

Permalink
fix(monitoring): Fixing flaky tests (#11202)
Browse files Browse the repository at this point in the history
* fix(monitoring): Fixing flaky tests

* fixing

* Trying to fix a test

* One more try to fix this...
  • Loading branch information
m-strzelczyk committed Feb 15, 2024
1 parent 1985da6 commit ff4c1d5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions monitoring/snippets/v3/cloud-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import os

import backoff
from google.api_core.exceptions import InternalServerError
from google.api_core.exceptions import NotFound
from google.api_core.exceptions import ServerError
from google.api_core.exceptions import ServiceUnavailable
import pytest

Expand Down Expand Up @@ -44,11 +44,18 @@ def custom_metric_descriptor() -> None:

@pytest.fixture(scope="module")
def write_time_series() -> None:
@backoff.on_exception(backoff.expo, InternalServerError, max_time=120)
@backoff.on_exception(backoff.expo, ServerError, max_time=120)
def write():
snippets.write_time_series(PROJECT_ID)

write()
try:
write()
except ServerError:
#
pytest.skip(
"Failed to prepare test fixture due to Internal server error. Not our fault 🤷"
)

yield


Expand All @@ -68,7 +75,8 @@ def eventually_consistent_test():
@backoff.on_exception(backoff.expo, (ServiceUnavailable), max_tries=3)
def test_list_metric_descriptors() -> None:
result = snippets.list_metric_descriptors(PROJECT_ID)
assert any(item.type == "logging.googleapis.com/byte_count" for item in result)
results = [item.type for item in result]
assert "logging.googleapis.com/byte_count" in results


@backoff.on_exception(backoff.expo, (ServiceUnavailable), max_tries=3)
Expand Down

0 comments on commit ff4c1d5

Please sign in to comment.