Skip to content

Commit 3d92e61

Browse files
author
Takashi Matsuo
committed
30 seconds operation wait and 20 minutes retry delay
1 parent dd542ad commit 3d92e61

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

dlp/risk_test.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
BIGQUERY_TABLE_ID = "dlp_test_table" + UNIQUE_STRING
3737
BIGQUERY_HARMFUL_TABLE_ID = "harmful" + UNIQUE_STRING
3838

39+
TIMEOUT=30
3940

4041
# Create new custom topic/subscription
4142
# We observe sometimes all the tests in this file fail. In a
@@ -163,7 +164,24 @@ def bigquery_project():
163164
bigquery_client.delete_dataset(dataset_ref, delete_contents=True)
164165

165166

166-
@pytest.mark.flaky(max_runs=5, min_passes=1)
167+
def delay():
168+
# 20 mins of delay. This sounds like too long a delay, but we
169+
# occasionally observe consequtive time block where operations are
170+
# slow which leads to the test failures. These situations tend to
171+
# get self healed in 20 minutes or so, so I'm trying this strategy.
172+
#
173+
# The worst case execution time becomes longer, but I think it
174+
# will give us higher success rate.
175+
#
176+
# There are ten tests, and each tests has 30 seconds wait time
177+
# and retried 1 times, so the worst case latency for the waits are:
178+
# 210 minutes (3 hours 30 minutes).
179+
# This might cause time out on Kokoro.
180+
time.sleep(60*20)
181+
return True
182+
183+
184+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
167185
def test_numerical_risk_analysis(
168186
topic_id, subscription_id, bigquery_project, capsys
169187
):
@@ -175,14 +193,14 @@ def test_numerical_risk_analysis(
175193
NUMERIC_FIELD,
176194
topic_id,
177195
subscription_id,
178-
timeout=30,
196+
timeout=TIMEOUT,
179197
)
180198

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

184202

185-
@pytest.mark.flaky(max_runs=5, min_passes=1)
203+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
186204
def test_categorical_risk_analysis_on_string_field(
187205
topic_id, subscription_id, bigquery_project, capsys
188206
):
@@ -194,14 +212,14 @@ def test_categorical_risk_analysis_on_string_field(
194212
UNIQUE_FIELD,
195213
topic_id,
196214
subscription_id,
197-
timeout=30,
215+
timeout=TIMEOUT,
198216
)
199217

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

203221

204-
@pytest.mark.flaky(max_runs=5, min_passes=1)
222+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
205223
def test_categorical_risk_analysis_on_number_field(
206224
topic_id, subscription_id, bigquery_project, capsys
207225
):
@@ -213,14 +231,14 @@ def test_categorical_risk_analysis_on_number_field(
213231
NUMERIC_FIELD,
214232
topic_id,
215233
subscription_id,
216-
timeout=30,
234+
timeout=TIMEOUT,
217235
)
218236

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

222240

223-
@pytest.mark.flaky(max_runs=5, min_passes=1)
241+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
224242
def test_k_anonymity_analysis_single_field(
225243
topic_id, subscription_id, bigquery_project, capsys
226244
):
@@ -232,15 +250,15 @@ def test_k_anonymity_analysis_single_field(
232250
topic_id,
233251
subscription_id,
234252
[NUMERIC_FIELD],
235-
timeout=30,
253+
timeout=TIMEOUT,
236254
)
237255

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

242260

243-
@pytest.mark.flaky(max_runs=5, min_passes=1)
261+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
244262
def test_k_anonymity_analysis_multiple_fields(
245263
topic_id, subscription_id, bigquery_project, capsys
246264
):
@@ -252,15 +270,15 @@ def test_k_anonymity_analysis_multiple_fields(
252270
topic_id,
253271
subscription_id,
254272
[NUMERIC_FIELD, REPEATED_FIELD],
255-
timeout=30,
273+
timeout=TIMEOUT,
256274
)
257275

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

262280

263-
@pytest.mark.flaky(max_runs=5, min_passes=1)
281+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
264282
def test_l_diversity_analysis_single_field(
265283
topic_id, subscription_id, bigquery_project, capsys
266284
):
@@ -273,7 +291,7 @@ def test_l_diversity_analysis_single_field(
273291
subscription_id,
274292
UNIQUE_FIELD,
275293
[NUMERIC_FIELD],
276-
timeout=30,
294+
timeout=TIMEOUT,
277295
)
278296

279297
out, _ = capsys.readouterr()
@@ -282,7 +300,7 @@ def test_l_diversity_analysis_single_field(
282300
assert "Sensitive value" in out
283301

284302

285-
@pytest.mark.flaky(max_runs=5, min_passes=1)
303+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
286304
def test_l_diversity_analysis_multiple_field(
287305
topic_id, subscription_id, bigquery_project, capsys
288306
):
@@ -295,7 +313,7 @@ def test_l_diversity_analysis_multiple_field(
295313
subscription_id,
296314
UNIQUE_FIELD,
297315
[NUMERIC_FIELD, REPEATED_FIELD],
298-
timeout=30,
316+
timeout=TIMEOUT,
299317
)
300318

301319
out, _ = capsys.readouterr()
@@ -304,7 +322,7 @@ def test_l_diversity_analysis_multiple_field(
304322
assert "Sensitive value" in out
305323

306324

307-
@pytest.mark.flaky(max_runs=5, min_passes=1)
325+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
308326
def test_k_map_estimate_analysis_single_field(
309327
topic_id, subscription_id, bigquery_project, capsys
310328
):
@@ -317,7 +335,7 @@ def test_k_map_estimate_analysis_single_field(
317335
subscription_id,
318336
[NUMERIC_FIELD],
319337
["AGE"],
320-
timeout=30,
338+
timeout=TIMEOUT,
321339
)
322340

323341
out, _ = capsys.readouterr()
@@ -326,7 +344,7 @@ def test_k_map_estimate_analysis_single_field(
326344
assert "Values" in out
327345

328346

329-
@pytest.mark.flaky(max_runs=5, min_passes=1)
347+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
330348
def test_k_map_estimate_analysis_multiple_field(
331349
topic_id, subscription_id, bigquery_project, capsys
332350
):
@@ -339,7 +357,7 @@ def test_k_map_estimate_analysis_multiple_field(
339357
subscription_id,
340358
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
341359
["AGE", "GENDER"],
342-
timeout=30,
360+
timeout=TIMEOUT,
343361
)
344362

345363
out, _ = capsys.readouterr()
@@ -348,7 +366,7 @@ def test_k_map_estimate_analysis_multiple_field(
348366
assert "Values" in out
349367

350368

351-
@pytest.mark.flaky(max_runs=5, min_passes=1)
369+
@pytest.mark.flaky(max_runs=2, min_passes=1, rerun_filter=delay)
352370
def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
353371
topic_id, subscription_id, bigquery_project
354372
):
@@ -362,5 +380,5 @@ def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
362380
subscription_id,
363381
[NUMERIC_FIELD, STRING_BOOLEAN_FIELD],
364382
["AGE"],
365-
timeout=30,
383+
timeout=TIMEOUT,
366384
)

0 commit comments

Comments
 (0)