Skip to content

Commit 4262575

Browse files
author
Takashi Matsuo
committed
limit the max retry wait time
1 parent 906ad3e commit 4262575

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

dlp/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the 'License');
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an 'AS IS' BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pytest
16+
17+
18+
# Used in risk_test.py to limit the maximum wait time before the flaky retries.
19+
def pytest_configure(config):
20+
pytest.MAX_FLAKY_WAIT = 3600 # maximum of an hour

dlp/risk_test.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,12 @@ def delay(err, *args):
172172
# slow which leads to the test failures. These situations tend to
173173
# get self healed in 20 minutes or so, so I'm trying this strategy.
174174
#
175-
# The worst case execution time becomes longer, but I think it
176-
# will give us higher success rate.
177-
#
178-
# There are ten tests, and each tests has 30 seconds wait time
179-
# and retried 1 times, so the worst case latency for the waits are:
180-
# 210 minutes (3 hours 30 minutes).
181-
# This might cause time out on Kokoro.
182-
time.sleep(60*20)
175+
# There are 10 tests, so we don't want the retry delay happening
176+
# for all the tests. When we exhaust the MAX_FLAKY_WAIT, we retry
177+
# the test immediately.
178+
wait_time = min(pytest.MAX_FLAKY_WAIT, 60*20)
179+
pytest.MAX_FLAKY_WAIT -= wait_time
180+
time.sleep(wait_time)
183181
return True
184182

185183

0 commit comments

Comments
 (0)