|
|
@ -1,18 +1,14 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
#!/usr/bin/env python3 |
|
|
|
import os |
|
|
|
import os |
|
|
|
import shutil |
|
|
|
|
|
|
|
import unittest |
|
|
|
import unittest |
|
|
|
|
|
|
|
from openpilot.tools.lib.url_file import URLFile |
|
|
|
os.environ["COMMA_CACHE"] = "/tmp/__test_cache__" |
|
|
|
from tools.lib.tests import temporary_cache_dir |
|
|
|
from openpilot.tools.lib.url_file import URLFile, CACHE_DIR |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFileDownload(unittest.TestCase): |
|
|
|
class TestFileDownload(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
def compare_loads(self, url, start=0, length=None): |
|
|
|
def compare_loads(self, url, start=0, length=None): |
|
|
|
"""Compares range between cached and non cached version""" |
|
|
|
"""Compares range between cached and non cached version""" |
|
|
|
shutil.rmtree(CACHE_DIR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file_cached = URLFile(url, cache=True) |
|
|
|
file_cached = URLFile(url, cache=True) |
|
|
|
file_downloaded = URLFile(url, cache=False) |
|
|
|
file_downloaded = URLFile(url, cache=False) |
|
|
|
|
|
|
|
|
|
|
@ -35,6 +31,7 @@ class TestFileDownload(unittest.TestCase): |
|
|
|
self.assertEqual(file_cached.get_length(), file_downloaded.get_length()) |
|
|
|
self.assertEqual(file_cached.get_length(), file_downloaded.get_length()) |
|
|
|
self.assertEqual(response_cached, response_downloaded) |
|
|
|
self.assertEqual(response_cached, response_downloaded) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@temporary_cache_dir |
|
|
|
def test_small_file(self): |
|
|
|
def test_small_file(self): |
|
|
|
# Make sure we don't force cache |
|
|
|
# Make sure we don't force cache |
|
|
|
os.environ["FILEREADER_CACHE"] = "0" |
|
|
|
os.environ["FILEREADER_CACHE"] = "0" |
|
|
@ -55,6 +52,7 @@ class TestFileDownload(unittest.TestCase): |
|
|
|
for i in range(length // 100): |
|
|
|
for i in range(length // 100): |
|
|
|
self.compare_loads(small_file_url, 100 * i, 100) |
|
|
|
self.compare_loads(small_file_url, 100 * i, 100) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@temporary_cache_dir |
|
|
|
def test_large_file(self): |
|
|
|
def test_large_file(self): |
|
|
|
large_file_url = "https://commadataci.blob.core.windows.net/openpilotci/0375fdf7b1ce594d/2019-06-13--08-32-25/3/qlog.bz2" |
|
|
|
large_file_url = "https://commadataci.blob.core.windows.net/openpilotci/0375fdf7b1ce594d/2019-06-13--08-32-25/3/qlog.bz2" |
|
|
|
# Load the end 100 bytes of both files |
|
|
|
# Load the end 100 bytes of both files |
|
|
|