Add serialized download queue with transfer speed and ETA

This commit is contained in:
Mikei386
2026-09-28 22:44:36 +02:00
parent 18a5183719
commit 43c8d6456c
5 changed files with 72 additions and 24 deletions
+25
View File
@@ -66,6 +66,31 @@ class CatalogTests(unittest.TestCase):
with self.assertRaises(ValueError):c.start('a/b','m.gguf','a'*40,'chat')
with patch('catalog.shutil.disk_usage',return_value=type('Disk',(),{'free':1024})()):
with self.assertRaises(ValueError):c.start('a/b','m.gguf','b'*40,'chat')
def test_queue_progress_duplicate_and_removal(self):
import threading
release=threading.Event();progress=threading.Event()
class Stream(io.BytesIO):
def read(self,n=-1):
if self.tell()==0:
time.sleep(.3);return super().read(1)
progress.set();release.wait(3);return super().read(n)
with tempfile.TemporaryDirectory() as d:
c=Catalog(d);data=dict(repo='a/b',revision='a'*40,gated=False,files=[dict(name=n,size=2,sha256=None) for n in ['a.gguf','b.gguf','c.gguf']])
with patch.object(c,'files',return_value=data),patch('catalog.remote',side_effect=[Stream(b'aa'),io.BytesIO(b'bb')]),patch('catalog.shutil.disk_usage',return_value=type('Disk',(),{'free':100*1024**3})()):
first=c.start('a/b','a.gguf','a'*40,'chat');self.assertTrue(progress.wait(2))
status=c.status()['job'];self.assertGreater(status['bytes_per_second'],0);self.assertGreater(status['eta_seconds'],0)
second=c.start('a/b','b.gguf','a'*40,'chat');self.assertEqual(second['state'],'queued')
with self.assertRaises(ValueError):c.start('a/b','b.gguf','a'*40,'chat')
third=c.start('a/b','c.gguf','a'*40,'chat');c.dismiss(third['id'])
release.set()
for _ in range(200):
if len(c.status()['entries'])==2 and c.status()['job']['state']=='complete':break
time.sleep(.01)
self.assertEqual(len(c.status()['entries']),2);self.assertEqual(c.status()['job']['id'],second['id']);self.assertFalse(c.pending)
def test_shutdown_does_not_start_queued_file(self):
with tempfile.TemporaryDirectory() as d:
c=Catalog(d);c.pending=[('sentinel',)];c.stop(shutdown=True)
with patch('catalog.threading.Thread') as thread:c._next();thread.assert_not_called()
def test_cancellation(self):
with tempfile.TemporaryDirectory() as directory:
c=Catalog(directory);c.job=dict(state='downloading');c.stop()