DownloadStatus: show active immutable downloads in Active Operations, Fix #1172

This commit is contained in:
francois 2010-09-02 03:17:28 -07:00
parent cdc625e0f8
commit 485bfc0fd6
2 changed files with 21 additions and 1 deletions

View File

@ -202,8 +202,15 @@ class DownloadStatus:
def using_helper(self):
return False
def get_active(self):
return False # TODO
# a download is considered active if it has at least one outstanding
# read() call
for r_ev in self.read_events:
if r_ev["finish_time"] is None:
return True
return False
def get_started(self):
return self.started
def get_results(self):

View File

@ -1259,6 +1259,19 @@ class Status(unittest.TestCase):
e2.finished(now+5)
self.failUnlessEqual(ds.get_progress(), 1.0)
def test_active(self):
now = 12345.1
ds = DownloadStatus("si-1", 123)
self.failUnlessEqual(ds.get_active(), False)
e1 = ds.add_read_event(0, 1000, now)
self.failUnlessEqual(ds.get_active(), True)
e2 = ds.add_read_event(1, 1000, now+1)
self.failUnlessEqual(ds.get_active(), True)
e1.finished(now+2)
self.failUnlessEqual(ds.get_active(), True)
e2.finished(now+3)
self.failUnlessEqual(ds.get_active(), False)
class MyShare:
def __init__(self, shnum, peerid, rtt):
self._shnum = shnum