36
36
BIGQUERY_TABLE_ID = "dlp_test_table" + UNIQUE_STRING
37
37
BIGQUERY_HARMFUL_TABLE_ID = "harmful" + UNIQUE_STRING
38
38
39
+ TIMEOUT = 30
39
40
40
41
# Create new custom topic/subscription
41
42
# We observe sometimes all the tests in this file fail. In a
@@ -163,7 +164,24 @@ def bigquery_project():
163
164
bigquery_client .delete_dataset (dataset_ref , delete_contents = True )
164
165
165
166
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 )
167
185
def test_numerical_risk_analysis (
168
186
topic_id , subscription_id , bigquery_project , capsys
169
187
):
@@ -175,14 +193,14 @@ def test_numerical_risk_analysis(
175
193
NUMERIC_FIELD ,
176
194
topic_id ,
177
195
subscription_id ,
178
- timeout = 30 ,
196
+ timeout = TIMEOUT ,
179
197
)
180
198
181
199
out , _ = capsys .readouterr ()
182
200
assert "Value Range:" in out
183
201
184
202
185
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
203
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
186
204
def test_categorical_risk_analysis_on_string_field (
187
205
topic_id , subscription_id , bigquery_project , capsys
188
206
):
@@ -194,14 +212,14 @@ def test_categorical_risk_analysis_on_string_field(
194
212
UNIQUE_FIELD ,
195
213
topic_id ,
196
214
subscription_id ,
197
- timeout = 30 ,
215
+ timeout = TIMEOUT ,
198
216
)
199
217
200
218
out , _ = capsys .readouterr ()
201
219
assert "Most common value occurs" in out
202
220
203
221
204
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
222
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
205
223
def test_categorical_risk_analysis_on_number_field (
206
224
topic_id , subscription_id , bigquery_project , capsys
207
225
):
@@ -213,14 +231,14 @@ def test_categorical_risk_analysis_on_number_field(
213
231
NUMERIC_FIELD ,
214
232
topic_id ,
215
233
subscription_id ,
216
- timeout = 30 ,
234
+ timeout = TIMEOUT ,
217
235
)
218
236
219
237
out , _ = capsys .readouterr ()
220
238
assert "Most common value occurs" in out
221
239
222
240
223
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
241
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
224
242
def test_k_anonymity_analysis_single_field (
225
243
topic_id , subscription_id , bigquery_project , capsys
226
244
):
@@ -232,15 +250,15 @@ def test_k_anonymity_analysis_single_field(
232
250
topic_id ,
233
251
subscription_id ,
234
252
[NUMERIC_FIELD ],
235
- timeout = 30 ,
253
+ timeout = TIMEOUT ,
236
254
)
237
255
238
256
out , _ = capsys .readouterr ()
239
257
assert "Quasi-ID values:" in out
240
258
assert "Class size:" in out
241
259
242
260
243
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
261
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
244
262
def test_k_anonymity_analysis_multiple_fields (
245
263
topic_id , subscription_id , bigquery_project , capsys
246
264
):
@@ -252,15 +270,15 @@ def test_k_anonymity_analysis_multiple_fields(
252
270
topic_id ,
253
271
subscription_id ,
254
272
[NUMERIC_FIELD , REPEATED_FIELD ],
255
- timeout = 30 ,
273
+ timeout = TIMEOUT ,
256
274
)
257
275
258
276
out , _ = capsys .readouterr ()
259
277
assert "Quasi-ID values:" in out
260
278
assert "Class size:" in out
261
279
262
280
263
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
281
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
264
282
def test_l_diversity_analysis_single_field (
265
283
topic_id , subscription_id , bigquery_project , capsys
266
284
):
@@ -273,7 +291,7 @@ def test_l_diversity_analysis_single_field(
273
291
subscription_id ,
274
292
UNIQUE_FIELD ,
275
293
[NUMERIC_FIELD ],
276
- timeout = 30 ,
294
+ timeout = TIMEOUT ,
277
295
)
278
296
279
297
out , _ = capsys .readouterr ()
@@ -282,7 +300,7 @@ def test_l_diversity_analysis_single_field(
282
300
assert "Sensitive value" in out
283
301
284
302
285
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
303
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
286
304
def test_l_diversity_analysis_multiple_field (
287
305
topic_id , subscription_id , bigquery_project , capsys
288
306
):
@@ -295,7 +313,7 @@ def test_l_diversity_analysis_multiple_field(
295
313
subscription_id ,
296
314
UNIQUE_FIELD ,
297
315
[NUMERIC_FIELD , REPEATED_FIELD ],
298
- timeout = 30 ,
316
+ timeout = TIMEOUT ,
299
317
)
300
318
301
319
out , _ = capsys .readouterr ()
@@ -304,7 +322,7 @@ def test_l_diversity_analysis_multiple_field(
304
322
assert "Sensitive value" in out
305
323
306
324
307
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
325
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
308
326
def test_k_map_estimate_analysis_single_field (
309
327
topic_id , subscription_id , bigquery_project , capsys
310
328
):
@@ -317,7 +335,7 @@ def test_k_map_estimate_analysis_single_field(
317
335
subscription_id ,
318
336
[NUMERIC_FIELD ],
319
337
["AGE" ],
320
- timeout = 30 ,
338
+ timeout = TIMEOUT ,
321
339
)
322
340
323
341
out , _ = capsys .readouterr ()
@@ -326,7 +344,7 @@ def test_k_map_estimate_analysis_single_field(
326
344
assert "Values" in out
327
345
328
346
329
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
347
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
330
348
def test_k_map_estimate_analysis_multiple_field (
331
349
topic_id , subscription_id , bigquery_project , capsys
332
350
):
@@ -339,7 +357,7 @@ def test_k_map_estimate_analysis_multiple_field(
339
357
subscription_id ,
340
358
[NUMERIC_FIELD , STRING_BOOLEAN_FIELD ],
341
359
["AGE" , "GENDER" ],
342
- timeout = 30 ,
360
+ timeout = TIMEOUT ,
343
361
)
344
362
345
363
out , _ = capsys .readouterr ()
@@ -348,7 +366,7 @@ def test_k_map_estimate_analysis_multiple_field(
348
366
assert "Values" in out
349
367
350
368
351
- @pytest .mark .flaky (max_runs = 5 , min_passes = 1 )
369
+ @pytest .mark .flaky (max_runs = 2 , min_passes = 1 , rerun_filter = delay )
352
370
def test_k_map_estimate_analysis_quasi_ids_info_types_equal (
353
371
topic_id , subscription_id , bigquery_project
354
372
):
@@ -362,5 +380,5 @@ def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
362
380
subscription_id ,
363
381
[NUMERIC_FIELD , STRING_BOOLEAN_FIELD ],
364
382
["AGE" ],
365
- timeout = 30 ,
383
+ timeout = TIMEOUT ,
366
384
)
0 commit comments