GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PubSub: Add system tests for PubSub clients by plamut · Pull Request #8277 · googleapis/google-cloud-python

PubSub: Add system tests for PubSub clients #8277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
plamut merged 6 commits into googleapis:master from plamut:iss-4031
Jun 21, 2019

Uh oh!

There was an error while loading. Please reload this page.

Merged

PubSub: Add system tests for PubSub clients #8277

Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
91622a9
Add system tests for listing topics, subscriptions
plamut Jun 7, 2019
70dc7aa
Add system test for listing topic's subscriptions
plamut Jun 7, 2019
3cb7351
Add system test for using PubSub snapshots
plamut Jun 10, 2019
5cf148f
Add PubSub system tests for managing IAM policy
plamut Jun 10, 2019
3545b17
Add test for creating non-default subscriptions
plamut Jun 11, 2019
3c13d50
Remove flaky PubSub snapshots system test
plamut Jun 12, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

171 changes: 171 additions & 0 deletions 171 pubsub/tests/system.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import datetime
import itertools
import operator as op
import threading
import time

Expand Down Expand Up @@ -183,6 +184,176 @@ def test_subscribe_to_messages_async_callbacks(
future.cancel()


def test_creating_subscriptions_with_non_default_settings(
publisher, subscriber, project, topic_path, subscription_path, cleanup
):
# Make sure the topic and subscription get deleted.
cleanup.append((publisher.delete_topic, topic_path))
cleanup.append((subscriber.delete_subscription, subscription_path))

# create a topic and a subscription, customize the latter's policy
publisher.create_topic(topic_path)

msg_retention_duration = {"seconds": 911}
expiration_policy = {"ttl": {"seconds": 90210}}
new_subscription = subscriber.create_subscription(
subscription_path,
topic_path,
ack_deadline_seconds=30,
retain_acked_messages=True,
message_retention_duration=msg_retention_duration,
expiration_policy=expiration_policy,
)

# fetch the subscription and check its settings
project_path = subscriber.project_path(project)
subscriptions = subscriber.list_subscriptions(project_path)

subscriptions = [sub for sub in subscriptions if sub.topic == topic_path]
assert len(subscriptions) == 1
subscription = subscriptions[0]

assert subscription == new_subscription
assert subscription.ack_deadline_seconds == 30
assert subscription.retain_acked_messages
assert subscription.message_retention_duration.seconds == 911
assert subscription.expiration_policy.ttl.seconds == 90210


def test_listing_project_topics(publisher, project, cleanup):
topic_paths = [
publisher.topic_path(project, "topic-{}".format(i) + unique_resource_id("."))
for i in range(1, 4)
]
for topic in topic_paths:
cleanup.append((publisher.delete_topic, topic))
publisher.create_topic(topic)

project_path = publisher.project_path(project)
project_topics = publisher.list_topics(project_path)
project_topics = set(t.name for t in project_topics)

# there might be other topics in the project, thus do a "is subset" check
assert set(topic_paths) <= project_topics


def test_listing_project_subscriptions(publisher, subscriber, project, cleanup):
# create topics
topic_paths = [
publisher.topic_path(project, "topic-1" + unique_resource_id(".")),
publisher.topic_path(project, "topic-2" + unique_resource_id(".")),
]
for topic in topic_paths:
cleanup.append((publisher.delete_topic, topic))
publisher.create_topic(topic)

# create subscriptions
subscription_paths = [
subscriber.subscription_path(
project, "sub-{}".format(i) + unique_resource_id(".")
)
for i in range(1, 4)
]
for i, subscription in enumerate(subscription_paths):
topic = topic_paths[i % 2]
cleanup.append((subscriber.delete_subscription, subscription))
subscriber.create_subscription(subscription, topic)

# retrieve subscriptions and check that the list matches the expected
project_path = subscriber.project_path(project)
subscriptions = subscriber.list_subscriptions(project_path)
subscriptions = set(s.name for s in subscriptions)

# there might be other subscriptions in the project, thus do a "is subset" check
assert set(subscription_paths) <= subscriptions


def test_listing_topic_subscriptions(publisher, subscriber, project, cleanup):
# create topics
topic_paths = [
publisher.topic_path(project, "topic-1" + unique_resource_id(".")),
publisher.topic_path(project, "topic-2" + unique_resource_id(".")),
]
for topic in topic_paths:
cleanup.append((publisher.delete_topic, topic))
publisher.create_topic(topic)

# create subscriptions
subscription_paths = [
subscriber.subscription_path(
project, "sub-{}".format(i) + unique_resource_id(".")
)
for i in range(1, 4)
]
for i, subscription in enumerate(subscription_paths):
topic = topic_paths[i % 2]
cleanup.append((subscriber.delete_subscription, subscription))
subscriber.create_subscription(subscription, topic)

# retrieve subscriptions and check that the list matches the expected
subscriptions = publisher.list_topic_subscriptions(topic_paths[0])
subscriptions = set(subscriptions)

assert subscriptions == {subscription_paths[0], subscription_paths[2]}


def test_managing_topic_iam_policy(publisher, topic_path, cleanup):
cleanup.append((publisher.delete_topic, topic_path))

# create a topic and customize its policy
publisher.create_topic(topic_path)
topic_policy = publisher.get_iam_policy(topic_path)

topic_policy.bindings.add(role="roles/pubsub.editor", members=["domain:google.com"])
topic_policy.bindings.add(
role="roles/pubsub.viewer", members=["group:[email protected]"]
)
new_policy = publisher.set_iam_policy(topic_path, topic_policy)

# fetch the topic policy again and check its values
topic_policy = publisher.get_iam_policy(topic_path)
assert topic_policy.bindings == new_policy.bindings
assert len(topic_policy.bindings) == 2

bindings = sorted(topic_policy.bindings, key=op.attrgetter("role"))
assert bindings[0].role == "roles/pubsub.editor"
assert bindings[0].members == ["domain:google.com"]

assert bindings[1].role == "roles/pubsub.viewer"
assert bindings[1].members == ["group:[email protected]"]


def test_managing_subscription_iam_policy(
publisher, subscriber, topic_path, subscription_path, cleanup
):
# Make sure the topic and subscription get deleted.
cleanup.append((publisher.delete_topic, topic_path))
cleanup.append((subscriber.delete_subscription, subscription_path))

# create a topic and a subscription, customize the latter's policy
publisher.create_topic(topic_path)
subscriber.create_subscription(subscription_path, topic_path)
sub_policy = subscriber.get_iam_policy(subscription_path)

sub_policy.bindings.add(role="roles/pubsub.editor", members=["domain:google.com"])
sub_policy.bindings.add(
role="roles/pubsub.viewer", members=["group:[email protected]"]
)
new_policy = subscriber.set_iam_policy(subscription_path, sub_policy)

# fetch the subscription policy again and check its values
sub_policy = subscriber.get_iam_policy(subscription_path)
assert sub_policy.bindings == new_policy.bindings
assert len(sub_policy.bindings) == 2

bindings = sorted(sub_policy.bindings, key=op.attrgetter("role"))
assert bindings[0].role == "roles/pubsub.editor"
assert bindings[0].members == ["domain:google.com"]

assert bindings[1].role == "roles/pubsub.viewer"
assert bindings[1].members == ["group:[email protected]"]


class TestStreamingPull(object):
def test_streaming_pull_callback_error_propagation(
self, publisher, topic_path, subscriber, subscription_path, cleanup
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.