@@ -23,6 +23,17 @@ class DownloaderTests(unittest.TestCase):
23
23
Unit tests for checking downloader logic.
24
24
"""
25
25
26
+ def _setup_time_mock_for_download (self , mock_time , end_time ):
27
+ """Helper to setup time mock that handles logging system calls."""
28
+ call_count = [0 ]
29
+ def time_side_effect ():
30
+ call_count [0 ] += 1
31
+ if call_count [0 ] <= 2 : # First two calls (validation, start_time)
32
+ return 1000
33
+ else : # All subsequent calls (logging, duration calculation)
34
+ return end_time
35
+ mock_time .side_effect = time_side_effect
36
+
26
37
@patch ("time.time" , return_value = 1000 )
27
38
def test_run_link_expired (self , mock_time ):
28
39
settings = Mock ()
@@ -90,13 +101,17 @@ def test_run_get_response_not_ok(self, mock_time):
90
101
d .run ()
91
102
self .assertTrue ("404" in str (context .exception ))
92
103
93
- @patch ("time.time" , return_value = 1000 )
104
+ @patch ("time.time" )
94
105
def test_run_uncompressed_successful (self , mock_time ):
106
+ self ._setup_time_mock_for_download (mock_time , 1000.5 )
107
+
95
108
http_client = DatabricksHttpClient .get_instance ()
96
109
file_bytes = b"1234567890" * 10
97
110
settings = Mock (link_expiry_buffer_secs = 0 , download_timeout = 0 , use_proxy = False )
98
111
settings .is_lz4_compressed = False
112
+ settings .min_cloudfetch_download_speed = 1.0
99
113
result_link = Mock (bytesNum = 100 , expiryTime = 1001 )
114
+ result_link .fileLink = "https://s3.amazonaws.com/bucket/file.arrow?token=abc123"
100
115
101
116
with patch .object (
102
117
http_client ,
@@ -115,15 +130,19 @@ def test_run_uncompressed_successful(self, mock_time):
115
130
116
131
assert file .file_bytes == b"1234567890" * 10
117
132
118
- @patch ("time.time" , return_value = 1000 )
133
+ @patch ("time.time" )
119
134
def test_run_compressed_successful (self , mock_time ):
135
+ self ._setup_time_mock_for_download (mock_time , 1000.2 )
136
+
120
137
http_client = DatabricksHttpClient .get_instance ()
121
138
file_bytes = b"1234567890" * 10
122
139
compressed_bytes = b'\x04 "M\x18 h@d\x00 \x00 \x00 \x00 \x00 \x00 \x00 #\x14 \x00 \x00 \x00 \xaf 1234567890\n \x00 BP67890\x00 \x00 \x00 \x00 '
123
140
124
141
settings = Mock (link_expiry_buffer_secs = 0 , download_timeout = 0 , use_proxy = False )
125
142
settings .is_lz4_compressed = True
143
+ settings .min_cloudfetch_download_speed = 1.0
126
144
result_link = Mock (bytesNum = 100 , expiryTime = 1001 )
145
+ result_link .fileLink = "https://s3.amazonaws.com/bucket/file.arrow?token=xyz789"
127
146
with patch .object (
128
147
http_client ,
129
148
"execute" ,
0 commit comments