diff --git a/docs/pubsub_snippets.py b/docs/pubsub_snippets.py index 6d932f56fe06..b3eec76f8f22 100644 --- a/docs/pubsub_snippets.py +++ b/docs/pubsub_snippets.py @@ -311,24 +311,21 @@ def subscription_pull(client, to_delete): subscription.create() to_delete.append(subscription) - # [START subscription_pull_none_pending] - pulled = subscription.pull(max_messages=1) - # [END subscription_pull_none_pending] - assert len(pulled) == 0 - # [START subscription_pull_return_immediately] pulled = subscription.pull(return_immediately=True) # [END subscription_pull_return_immediately] - assert len(pulled) == 0 + assert len(pulled) == 0, "unexpected message" topic.publish(PAYLOAD1) topic.publish(PAYLOAD2, extra=EXTRA) + time.sleep(1) # eventually-consistent + # [START subscription_pull] pulled = subscription.pull(max_messages=2) # [END subscription_pull] - assert len(pulled) == 2 + assert len(pulled) == 2, "eventual consistency" # [START subscription_modify_ack_deadline] for ack_id, _ in pulled: diff --git a/gcloud/pubsub/connection.py b/gcloud/pubsub/connection.py index 01024b61bf53..196d58cea7a6 100644 --- a/gcloud/pubsub/connection.py +++ b/gcloud/pubsub/connection.py @@ -416,7 +416,7 @@ def subscription_pull(self, subscription_path, return_immediately=False, 'maxMessages': max_messages, } response = conn.api_request(method='POST', path=path, data=data) - return response['receivedMessages'] + return response.get('receivedMessages', ()) def subscription_acknowledge(self, subscription_path, ack_ids): """API call: acknowledge retrieved messages for the subscription.