Skip to content

Commit

Permalink
Tests: Remove shared subscriptions across parallel tests (#669)
Browse files Browse the repository at this point in the history
In samples/snippets/noxfile.py, tests are run in parallel if pytest-parallel is installed.

This resulted in tests failing in CI that did not fail locally. Because of the use of shared subscription names across tests running in parallel, some tests were deleting a subscription, while others were attempting to receive messages.

This PR removes all subscription test fixtures that created and deleted subscriptions that were reused across tests in samples/snippets/subscriber_test.py, instead repeating the creation logic within each test, with a different subscription name per test, to allow tests to run in parallel without failures.

Also includes unrelated formatting changes due to linting changes.

Fixes #668🦕
  • Loading branch information
acocuzzo committed May 16, 2022
1 parent f35831e commit 8513f53
Show file tree
Hide file tree
Showing 3 changed files with 475 additions and 397 deletions.
5 changes: 5 additions & 0 deletions samples/snippets/publisher_test.py
Expand Up @@ -28,13 +28,18 @@
import publisher


# This uuid is shared across tests which run in parallel.
UUID = uuid.uuid4().hex
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
TOPIC_ID = "publisher-test-topic-" + UUID
SUBSCRIPTION_ID = "publisher-test-subscription-" + UUID
# Allow 60s for tests to finish.
MAX_TIME = 60

# These tests run in parallel if pytest-parallel is installed.
# Avoid modifying resources that are shared across tests,
# as this results in test flake.

if typing.TYPE_CHECKING:
from unittest.mock import AsyncMock, MagicMock

Expand Down
5 changes: 5 additions & 0 deletions samples/snippets/schema_test.py
Expand Up @@ -31,6 +31,7 @@

import schema

# This uuid is shared across tests which run in parallel.
UUID = uuid.uuid4().hex
try:
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
Expand All @@ -45,6 +46,10 @@
AVSC_FILE = "resources/us-states.avsc"
PROTO_FILE = "resources/us-states.proto"

# These tests run in parallel if pytest-parallel is installed.
# Avoid modifying resources that are shared across tests,
# as this results in test flake.


@pytest.fixture(scope="module")
def schema_client() -> Generator[pubsub_v1.SchemaServiceClient, None, None]:
Expand Down

0 comments on commit 8513f53

Please sign in to comment.