Skip to content

Commit e62ce78

Browse files
committed
add compression to receive test
1 parent 90efd38 commit e62ce78

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

samples/snippets/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from google.cloud import pubsub_v1
2+
pub_sub_client = pubsub_v1.PublisherClient()
3+
4+
if __name__ == '__main__':
5+
result = pub_sub_client.publish("projects/annaco-python-lib-test/topics/annaco-python-lib-test-topic", bytes("Some message here!", "utf8")).result()

samples/snippets/sponge_log.xml -v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="24" time="23.343" timestamp="2022-04-22T15:12:12.032784" hostname="cs-872183299652-default"><testcase classname="samples.snippets.iam_test" name="test_get_topic_policy" time="3.244" /><testcase classname="samples.snippets.iam_test" name="test_get_subscription_policy" time="1.090" /><testcase classname="samples.snippets.iam_test" name="test_set_topic_policy" time="0.401" /><testcase classname="samples.snippets.iam_test" name="test_set_subscription_policy" time="0.400" /><testcase classname="samples.snippets.iam_test" name="test_check_topic_permissions" time="0.053" /><testcase classname="samples.snippets.iam_test" name="test_check_subscription_permissions" time="0.497" /><testcase classname="samples.snippets.publisher_test" name="test_create" time="1.904" /><testcase classname="samples.snippets.publisher_test" name="test_list" time="0.124" /><testcase classname="samples.snippets.publisher_test" name="test_publish" time="1.317" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_custom_attributes" time="0.858" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_batch_settings" time="1.261" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_flow_control_settings" time="0.836" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_retry_settings" time="0.572" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_error_handler" time="0.064" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_ordering_keys" time="1.423" /><testcase classname="samples.snippets.publisher_test" name="test_resume_publish_with_error_handler" time="0.562" /><testcase classname="samples.snippets.publisher_test" name="test_detach_subscription" time="1.520" /><testcase classname="samples.snippets.publisher_test" name="test_delete" time="0.607" /><testcase classname="samples.snippets.schema_test" name="test_create_avro_schema" time="0.522" /><testcase classname="samples.snippets.schema_test" name="test_create_proto_schema" time="0.225" /><testcase classname="samples.snippets.schema_test" name="test_get_schema" time="0.097" /><testcase classname="samples.snippets.schema_test" name="test_list_schemas" time="0.076" /><testcase classname="samples.snippets.schema_test" name="test_create_topic_with_schema" time="2.364" /><testcase classname="samples.snippets.schema_test" name="test_publish_avro_records" time="0.499" /><testcase time="0.925" /></testsuite></testsuites>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="51" time="244.740" timestamp="2022-04-22T15:13:22.043387" hostname="cs-872183299652-default"><testcase classname="samples.snippets.iam_test" name="test_get_topic_policy" time="2.263" /><testcase classname="samples.snippets.iam_test" name="test_get_subscription_policy" time="1.700" /><testcase classname="samples.snippets.iam_test" name="test_set_topic_policy" time="0.394" /><testcase classname="samples.snippets.iam_test" name="test_set_subscription_policy" time="0.498" /><testcase classname="samples.snippets.iam_test" name="test_check_topic_permissions" time="0.067" /><testcase classname="samples.snippets.iam_test" name="test_check_subscription_permissions" time="0.688" /><testcase classname="samples.snippets.publisher_test" name="test_create" time="2.598" /><testcase classname="samples.snippets.publisher_test" name="test_list" time="0.118" /><testcase classname="samples.snippets.publisher_test" name="test_publish" time="1.426" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_custom_attributes" time="1.010" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_batch_settings" time="1.071" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_flow_control_settings" time="0.671" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_retry_settings" time="0.435" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_error_handler" time="0.072" /><testcase classname="samples.snippets.publisher_test" name="test_publish_with_ordering_keys" time="1.472" /><testcase classname="samples.snippets.publisher_test" name="test_resume_publish_with_error_handler" time="0.587" /><testcase classname="samples.snippets.publisher_test" name="test_detach_subscription" time="1.885" /><testcase classname="samples.snippets.publisher_test" name="test_delete" time="0.749" /><testcase classname="samples.snippets.schema_test" name="test_create_avro_schema" time="0.395" /><testcase classname="samples.snippets.schema_test" name="test_create_proto_schema" time="0.330" /><testcase classname="samples.snippets.schema_test" name="test_get_schema" time="0.092" /><testcase classname="samples.snippets.schema_test" name="test_list_schemas" time="0.087" /><testcase classname="samples.snippets.schema_test" name="test_create_topic_with_schema" time="2.238" /><testcase classname="samples.snippets.schema_test" name="test_publish_avro_records" time="0.398" /><testcase classname="samples.snippets.schema_test" name="test_subscribe_with_avro_schema" time="10.028" /><testcase classname="samples.snippets.schema_test" name="test_publish_proto_records" time="2.963" /><testcase classname="samples.snippets.schema_test" name="test_subscribe_with_proto_schema" time="10.451" /><testcase classname="samples.snippets.schema_test" name="test_delete_schema" time="2.091" /><testcase classname="samples.snippets.subscriber_test" name="test_list_in_topic" time="3.186" /><testcase classname="samples.snippets.subscriber_test" name="test_list_in_project" time="0.079" /><testcase classname="samples.snippets.subscriber_test" name="test_create_subscription" time="1.097" /><testcase classname="samples.snippets.subscriber_test" name="test_create_subscription_with_dead_letter_policy" time="4.799" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_with_delivery_attempts" time="90.934" /><testcase classname="samples.snippets.subscriber_test" name="test_update_dead_letter_policy" time="0.234" /><testcase classname="samples.snippets.subscriber_test" name="test_remove_dead_letter_policy" time="0.285" /><testcase classname="samples.snippets.subscriber_test" name="test_create_subscription_with_ordering" time="1.163" /><testcase classname="samples.snippets.subscriber_test" name="test_create_subscription_with_filtering" time="1.167" /><testcase classname="samples.snippets.subscriber_test" name="test_create_subscription_with_exactly_once_delivery" time="6.503" /><testcase classname="samples.snippets.subscriber_test" name="test_create_push_subscription" time="2.292" /><testcase classname="samples.snippets.subscriber_test" name="test_update_push_suscription" time="0.380" /><testcase classname="samples.snippets.subscriber_test" name="test_delete_subscription" time="0.303" /><testcase classname="samples.snippets.subscriber_test" name="test_receive" time="6.855" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_with_custom_attributes" time="5.221" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_with_flow_control" time="5.257" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_with_blocking_shutdown" time="8.700" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_messages_with_exactly_once_delivery_enabled" time="12.036" /><testcase classname="samples.snippets.subscriber_test" name="test_listen_for_errors" time="5.240" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_synchronously" time="3.541" /><testcase classname="samples.snippets.subscriber_test" name="test_receive_synchronously_with_lease" time="23.804" /><testcase classname="samples.snippets.quickstart.quickstart_test" name="test_pub" time="2.808" /><testcase classname="samples.snippets.quickstart.quickstart_test" name="test_sub" time="11.505" /></testsuite></testsuites>

samples/snippets/subscriber_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
def publisher_client() -> Generator[pubsub_v1.PublisherClient, None, None]:
6363
yield pubsub_v1.PublisherClient()
6464

65+
@pytest.fixture(scope="module")
66+
def publisher_client_with_default_compression() -> Generator[pubsub_v1.PublisherClient, None, None]:
67+
yield pubsub_v1.PublisherClient(publisher_options=pubsub_v1.types.PublisherOptions(enable_grpc_compression=True))
68+
69+
@pytest.fixture(scope="module")
70+
def publisher_client_with_low_compression() -> Generator[pubsub_v1.PublisherClient, None, None]:
71+
yield pubsub_v1.PublisherClient(publisher_options=pubsub_v1.types.PublisherOptions(enable_grpc_compression=True, compression_bytes_threshold=0))
6572

6673
@pytest.fixture(scope="module")
6774
def regional_publisher_client() -> Generator[pubsub_v1.PublisherClient, None, None]:
@@ -791,6 +798,36 @@ def eventually_consistent_test() -> None:
791798
eventually_consistent_test()
792799

793800

801+
def test_listen_for_errors_default_compression(
802+
publisher_client_with_default_compression: pubsub_v1.PublisherClient,
803+
topic: str,
804+
subscription_async: str,
805+
capsys: CaptureFixture[str],
806+
) -> None:
807+
_ = _publish_messages(publisher_client_with_default_compression, topic)
808+
809+
subscriber.listen_for_errors(PROJECT_ID, SUBSCRIPTION_ASYNC, 5)
810+
811+
out, _ = capsys.readouterr()
812+
assert subscription_async in out
813+
assert "threw an exception" in out
814+
815+
816+
def test_listen_for_errors_low_compression(
817+
publisher_client_with_low_compression: pubsub_v1.PublisherClient,
818+
topic: str,
819+
subscription_async: str,
820+
capsys: CaptureFixture[str],
821+
) -> None:
822+
_ = _publish_messages(publisher_client_with_low_compression, topic)
823+
824+
subscriber.listen_for_errors(PROJECT_ID, SUBSCRIPTION_ASYNC, 5)
825+
826+
out, _ = capsys.readouterr()
827+
assert subscription_async in out
828+
assert "threw an exception" in out
829+
830+
794831
def test_receive_synchronously(
795832
publisher_client: pubsub_v1.PublisherClient,
796833
topic: str,

0 commit comments

Comments
 (0)