Skip to content

Commit

Permalink
[dlp] fix: mitigate flakiness
Browse files Browse the repository at this point in the history
* make the Pub/Sub fixture function level
* shorten the timeout for the tests from 300 secs to 30 secs
* retring all the tests in risk_test.py 3 times

fixes GoogleCloudPlatform#3897
fixes GoogleCloudPlatform#3896
fixes GoogleCloudPlatform#3895
fixes GoogleCloudPlatform#3894
fixes GoogleCloudPlatform#3893
fixes GoogleCloudPlatform#3892
fixes GoogleCloudPlatform#3890
fixes GoogleCloudPlatform#3889
  • Loading branch information
Takashi Matsuo committed May 31, 2020
1 parent d671543 commit 0f436e1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions dlp/risk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# Create new custom topic/subscription
@pytest.fixture(scope="module")
@pytest.fixture(scope="function")
def topic_id():
# Creates a pubsub topic, and tears it down.
publisher = google.cloud.pubsub.PublisherClient()
Expand All @@ -53,7 +53,7 @@ def topic_id():
publisher.delete_topic(topic_path)


@pytest.fixture(scope="module")
@pytest.fixture(scope="function")
def subscription_id(topic_id):
# Subscribes to a topic.
subscriber = google.cloud.pubsub.SubscriberClient()
Expand Down Expand Up @@ -160,7 +160,7 @@ def bigquery_project():
bigquery_client.delete_dataset(dataset_ref, delete_contents=True)


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_numerical_risk_analysis(
topic_id, subscription_id, bigquery_project, capsys
):
Expand All @@ -172,13 +172,14 @@ def test_numerical_risk_analysis(
NUMERIC_FIELD,
topic_id,
subscription_id,
timeout=30,
)

out, _ = capsys.readouterr()
assert "Value Range:" in out


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_categorical_risk_analysis_on_string_field(
topic_id, subscription_id, bigquery_project, capsys
):
Expand All @@ -190,14 +191,14 @@ def test_categorical_risk_analysis_on_string_field(
UNIQUE_FIELD,
topic_id,
subscription_id,
timeout=180,
timeout=30,
)

out, _ = capsys.readouterr()
assert "Most common value occurs" in out


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_categorical_risk_analysis_on_number_field(
topic_id, subscription_id, bigquery_project, capsys
):
Expand All @@ -209,13 +210,14 @@ def test_categorical_risk_analysis_on_number_field(
NUMERIC_FIELD,
topic_id,
subscription_id,
timeout=30,
)

out, _ = capsys.readouterr()
assert "Most common value occurs" in out


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_k_anonymity_analysis_single_field(
topic_id, subscription_id, bigquery_project, capsys
):
Expand All @@ -227,6 +229,7 @@ def test_k_anonymity_analysis_single_field(
topic_id,
subscription_id,
[NUMERIC_FIELD],
timeout=30,
)

out, _ = capsys.readouterr()
Expand All @@ -246,14 +249,15 @@ def test_k_anonymity_analysis_multiple_fields(
topic_id,
subscription_id,
[NUMERIC_FIELD, REPEATED_FIELD],
timeout=30,
)

out, _ = capsys.readouterr()
assert "Quasi-ID values:" in out
assert "Class size:" in out


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_l_diversity_analysis_single_field(
topic_id, subscription_id, bigquery_project, capsys
):
Expand All @@ -266,6 +270,7 @@ def test_l_diversity_analysis_single_field(
subscription_id,
UNIQUE_FIELD,
[NUMERIC_FIELD],
timeout=30,
)

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

out, _ = capsys.readouterr()
Expand All @@ -295,7 +301,7 @@ def test_l_diversity_analysis_multiple_field(
assert "Sensitive value" in out


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_k_map_estimate_analysis_single_field(
topic_id, subscription_id, bigquery_project, capsys
):
Expand All @@ -308,6 +314,7 @@ def test_k_map_estimate_analysis_single_field(
subscription_id,
[NUMERIC_FIELD],
["AGE"],
timeout=30,
)

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

out, _ = capsys.readouterr()
Expand All @@ -337,7 +345,7 @@ def test_k_map_estimate_analysis_multiple_field(
assert "Values" in out


@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
topic_id, subscription_id, bigquery_project
):
Expand All @@ -351,4 +359,5 @@ def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
subscription_id,
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
["AGE"],
timeout=30,
)

0 comments on commit 0f436e1

Please sign in to comment.