-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix memory leak while downloading large files #1707 #1736
Conversation
Added "MediaGenBaseDownload" class in order to fetch chunks using generator and to avoid memory leak issue.
Thanks for the fix @h3x4d1v1n3! Please could you add a test? |
Sure @parthea |
Hi @h3x4d1v1n3 & @parthea we can use the test below: import unittest
from unittest.mock import patch, MagicMock
import random
import time
class TestMediaGenBaseDownload(unittest.TestCase):
@patch('random.random')
@patch('time.sleep')
def test_next_chunk(self, mock_sleep, mock_random):
mock_random.return_value = 0
mock_sleep.return_value = None
# mock request object
request = MagicMock()
request.headers = {'accept': 'application/json'}
request.uri = 'https://test.com'
request.http = MagicMock()
# mock http object
request.http.request.return_value = (MagicMock(), b'content')
downloader = MediaGenBaseDownload(request)
# loop through the generator
for chunk, status, done in downloader.next_chunk():
self.assertEqual(chunk, b'content')
self.assertEqual(done, True)
self.assertIsInstance(status, MediaDownloadProgress)
In this test, I have mocked the |
@parthea could you check the latest comits for tests. Let me know your assessment... |
One of my commit do not have verified tag, causing it to fail CLA check. I will hard reset the commit and update the code with new branch. |
Added "MediaGenBaseDownload" class in order to fetch chunks using generator and to avoid memory leak issue.
Fixes #1706 🦕