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: Memory leak - issue while downloading large files #1736
base: main
Are you sure you want to change the base?
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? |
Hi @parthea, thank you for checking the PR. I would like to add test but I am quite not sure how it's done. |
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... |
Added "MediaGenBaseDownload" class in order to fetch chunks using generator and to avoid memory leak issue.
Fixes #1706 🦕