Skip to content

Commit 0f436e1

Browse files
author
Takashi Matsuo
committed
[dlp] fix: mitigate flakiness
* 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
1 parent d671543 commit 0f436e1

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

dlp/risk_test.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

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

5555

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

162162

163-
@pytest.mark.flaky
163+
@pytest.mark.flaky(max_runs=3, min_passes=1)
164164
def test_numerical_risk_analysis(
165165
topic_id, subscription_id, bigquery_project, capsys
166166
):
@@ -172,13 +172,14 @@ def test_numerical_risk_analysis(
172172
NUMERIC_FIELD,
173173
topic_id,
174174
subscription_id,
175+
timeout=30,
175176
)
176177

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

180181

181-
@pytest.mark.flaky
182+
@pytest.mark.flaky(max_runs=3, min_passes=1)
182183
def test_categorical_risk_analysis_on_string_field(
183184
topic_id, subscription_id, bigquery_project, capsys
184185
):
@@ -190,14 +191,14 @@ def test_categorical_risk_analysis_on_string_field(
190191
UNIQUE_FIELD,
191192
topic_id,
192193
subscription_id,
193-
timeout=180,
194+
timeout=30,
194195
)
195196

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

199200

200-
@pytest.mark.flaky
201+
@pytest.mark.flaky(max_runs=3, min_passes=1)
201202
def test_categorical_risk_analysis_on_number_field(
202203
topic_id, subscription_id, bigquery_project, capsys
203204
):
@@ -209,13 +210,14 @@ def test_categorical_risk_analysis_on_number_field(
209210
NUMERIC_FIELD,
210211
topic_id,
211212
subscription_id,
213+
timeout=30,
212214
)
213215

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

217219

218-
@pytest.mark.flaky
220+
@pytest.mark.flaky(max_runs=3, min_passes=1)
219221
def test_k_anonymity_analysis_single_field(
220222
topic_id, subscription_id, bigquery_project, capsys
221223
):
@@ -227,6 +229,7 @@ def test_k_anonymity_analysis_single_field(
227229
topic_id,
228230
subscription_id,
229231
[NUMERIC_FIELD],
232+
timeout=30,
230233
)
231234

232235
out, _ = capsys.readouterr()
@@ -246,14 +249,15 @@ def test_k_anonymity_analysis_multiple_fields(
246249
topic_id,
247250
subscription_id,
248251
[NUMERIC_FIELD, REPEATED_FIELD],
252+
timeout=30,
249253
)
250254

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

255259

256-
@pytest.mark.flaky
260+
@pytest.mark.flaky(max_runs=3, min_passes=1)
257261
def test_l_diversity_analysis_single_field(
258262
topic_id, subscription_id, bigquery_project, capsys
259263
):
@@ -266,6 +270,7 @@ def test_l_diversity_analysis_single_field(
266270
subscription_id,
267271
UNIQUE_FIELD,
268272
[NUMERIC_FIELD],
273+
timeout=30,
269274
)
270275

271276
out, _ = capsys.readouterr()
@@ -287,6 +292,7 @@ def test_l_diversity_analysis_multiple_field(
287292
subscription_id,
288293
UNIQUE_FIELD,
289294
[NUMERIC_FIELD, REPEATED_FIELD],
295+
timeout=30,
290296
)
291297

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

297303

298-
@pytest.mark.flaky
304+
@pytest.mark.flaky(max_runs=3, min_passes=1)
299305
def test_k_map_estimate_analysis_single_field(
300306
topic_id, subscription_id, bigquery_project, capsys
301307
):
@@ -308,6 +314,7 @@ def test_k_map_estimate_analysis_single_field(
308314
subscription_id,
309315
[NUMERIC_FIELD],
310316
["AGE"],
317+
timeout=30,
311318
)
312319

313320
out, _ = capsys.readouterr()
@@ -329,6 +336,7 @@ def test_k_map_estimate_analysis_multiple_field(
329336
subscription_id,
330337
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
331338
["AGE", "GENDER"],
339+
timeout=30,
332340
)
333341

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

339347

340-
@pytest.mark.flaky
348+
@pytest.mark.flaky(max_runs=3, min_passes=1)
341349
def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
342350
topic_id, subscription_id, bigquery_project
343351
):
@@ -351,4 +359,5 @@ def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
351359
subscription_id,
352360
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
353361
["AGE"],
362+
timeout=30,
354363
)

0 commit comments

Comments
 (0)