Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
6a43a1f8
"server/text_generation_server/models/flash_cohere.py" did not exist on "211b211ec0df7c44f920429b0ec6767af5c9ea80"
Unverified
Commit
6a43a1f8
authored
Sep 24, 2020
by
Philip Meier
Committed by
GitHub
Sep 24, 2020
Browse files
limit requests per time in download tests (#2699)
parent
1b415254
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
test/test_datasets_download.py
test/test_datasets_download.py
+32
-3
No files found.
test/test_datasets_download.py
View file @
6a43a1f8
import
contextlib
import
itertools
import
time
import
unittest
import
unittest.mock
from
datetime
import
datetime
from
os
import
path
from
tim
e
import
sleep
from
urllib.pars
e
import
urlparse
from
urllib.request
import
urlopen
,
Request
from
torchvision
import
datasets
...
...
@@ -13,6 +15,34 @@ from common_utils import get_tmp_dir
from
fakedata_generation
import
places365_root
def
limit_requests_per_time
(
min_secs_between_requests
=
2.0
):
last_requests
=
{}
def
outer_wrapper
(
fn
):
def
inner_wrapper
(
request
,
*
args
,
**
kwargs
):
url
=
request
.
full_url
if
isinstance
(
request
,
Request
)
else
request
netloc
=
urlparse
(
url
).
netloc
last_request
=
last_requests
.
get
(
netloc
)
if
last_request
is
not
None
:
elapsed_secs
=
(
datetime
.
now
()
-
last_request
).
total_seconds
()
delta
=
min_secs_between_requests
-
elapsed_secs
if
delta
>
0
:
time
.
sleep
(
delta
)
response
=
fn
(
request
,
*
args
,
**
kwargs
)
last_requests
[
netloc
]
=
datetime
.
now
()
return
response
return
inner_wrapper
return
outer_wrapper
urlopen
=
limit_requests_per_time
()(
urlopen
)
class
DownloadTester
(
unittest
.
TestCase
):
@
staticmethod
@
contextlib
.
contextmanager
...
...
@@ -37,7 +67,7 @@ class DownloadTester(unittest.TestCase):
return
fn
()
except
AssertionError
as
error
:
msgs
.
append
(
str
(
error
))
sleep
(
wait
)
time
.
sleep
(
wait
)
else
:
raise
AssertionError
(
"
\n
"
.
join
(
...
...
@@ -80,7 +110,6 @@ class DownloadTester(unittest.TestCase):
for
url
,
md5
in
self
.
collect_urls_and_md5s
():
with
self
.
subTest
(
url
=
url
,
md5
=
md5
):
self
.
retry
(
lambda
:
assert_fn
(
url
,
md5
))
sleep
(
2.0
)
def
collect_urls_and_md5s
(
self
):
raise
NotImplementedError
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment