Skip to content

Commit

Permalink
samples: increase timeout, catch concurrent.futures.TimeoutError (#266)
Browse files Browse the repository at this point in the history
* samples: catch concurrent.futures.TimeoutError

* fix: use default timeout in samples file
  • Loading branch information
busunkim96 authored Oct 5, 2021
1 parent 26aea2f commit bb011e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
15 changes: 10 additions & 5 deletions dlp/snippets/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def numerical_risk_analysis(
Returns:
None; the response from the API is printed to the terminal.
"""
import concurrent.futures

# Import the client library.
import google.cloud.dlp
Expand Down Expand Up @@ -116,7 +117,7 @@ def callback(message):

try:
subscription.result(timeout=timeout)
except TimeoutError:
except concurrent.futures.TimeoutError:
print(
"No event received before the timeout. Please verify that the "
"subscription provided is subscribed to the topic provided."
Expand Down Expand Up @@ -156,6 +157,7 @@ def categorical_risk_analysis(
Returns:
None; the response from the API is printed to the terminal.
"""
import concurrent.futures

# Import the client library.
import google.cloud.dlp
Expand Down Expand Up @@ -237,7 +239,7 @@ def callback(message):

try:
subscription.result(timeout=timeout)
except TimeoutError:
except concurrent.futures.TimeoutError:
print(
"No event received before the timeout. Please verify that the "
"subscription provided is subscribed to the topic provided."
Expand Down Expand Up @@ -277,6 +279,7 @@ def k_anonymity_analysis(
Returns:
None; the response from the API is printed to the terminal.
"""
import concurrent.futures

# Import the client library.
import google.cloud.dlp
Expand Down Expand Up @@ -367,7 +370,7 @@ def callback(message):

try:
subscription.result(timeout=timeout)
except TimeoutError:
except concurrent.futures.TimeoutError:
print(
"No event received before the timeout. Please verify that the "
"subscription provided is subscribed to the topic provided."
Expand Down Expand Up @@ -409,6 +412,7 @@ def l_diversity_analysis(
Returns:
None; the response from the API is printed to the terminal.
"""
import concurrent.futures

# Import the client library.
import google.cloud.dlp
Expand Down Expand Up @@ -509,7 +513,7 @@ def callback(message):

try:
subscription.result(timeout=timeout)
except TimeoutError:
except concurrent.futures.TimeoutError:
print(
"No event received before the timeout. Please verify that the "
"subscription provided is subscribed to the topic provided."
Expand Down Expand Up @@ -558,6 +562,7 @@ def k_map_estimate_analysis(
Returns:
None; the response from the API is printed to the terminal.
"""
import concurrent.futures

# Import the client library.
import google.cloud.dlp
Expand Down Expand Up @@ -659,7 +664,7 @@ def callback(message):

try:
subscription.result(timeout=timeout)
except TimeoutError:
except concurrent.futures.TimeoutError:
print(
"No event received before the timeout. Please verify that the "
"subscription provided is subscribed to the topic provided."
Expand Down
12 changes: 0 additions & 12 deletions dlp/snippets/risk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
BIGQUERY_TABLE_ID = "dlp_test_table" + UNIQUE_STRING
BIGQUERY_HARMFUL_TABLE_ID = "harmful" + UNIQUE_STRING

TIMEOUT = 120 # 2 minutes


# Create new custom topic/subscription
# We observe sometimes all the tests in this file fail. In a
Expand Down Expand Up @@ -173,7 +171,6 @@ def test_numerical_risk_analysis(topic_id, subscription_id, bigquery_project, ca
NUMERIC_FIELD,
topic_id,
subscription_id,
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -192,7 +189,6 @@ def test_categorical_risk_analysis_on_string_field(
UNIQUE_FIELD,
topic_id,
subscription_id,
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -211,7 +207,6 @@ def test_categorical_risk_analysis_on_number_field(
NUMERIC_FIELD,
topic_id,
subscription_id,
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -230,7 +225,6 @@ def test_k_anonymity_analysis_single_field(
topic_id,
subscription_id,
[NUMERIC_FIELD],
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -250,7 +244,6 @@ def test_k_anonymity_analysis_multiple_fields(
topic_id,
subscription_id,
[NUMERIC_FIELD, REPEATED_FIELD],
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -271,7 +264,6 @@ def test_l_diversity_analysis_single_field(
subscription_id,
UNIQUE_FIELD,
[NUMERIC_FIELD],
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -293,7 +285,6 @@ def test_l_diversity_analysis_multiple_field(
subscription_id,
UNIQUE_FIELD,
[NUMERIC_FIELD, REPEATED_FIELD],
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -315,7 +306,6 @@ def test_k_map_estimate_analysis_single_field(
subscription_id,
[NUMERIC_FIELD],
["AGE"],
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -337,7 +327,6 @@ def test_k_map_estimate_analysis_multiple_field(
subscription_id,
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
["AGE", "GENDER"],
timeout=TIMEOUT,
)

out, _ = capsys.readouterr()
Expand All @@ -360,5 +349,4 @@ def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
subscription_id,
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
["AGE"],
timeout=TIMEOUT,
)

0 comments on commit bb011e1

Please sign in to comment.