From: francois Date: Thu, 2 Sep 2010 10:17:28 +0000 (-0700) Subject: DownloadStatus: show active immutable downloads in Active Operations, Fix #1172 X-Git-Tag: allmydata-tahoe-1.8.0c3~3 X-Git-Url: https://git.rkrishnan.org/specifications/%5B%5E?a=commitdiff_plain;h=485bfc0fd67ef42130444622c9a5f3c18cd18a3d;p=tahoe-lafs%2Ftahoe-lafs.git DownloadStatus: show active immutable downloads in Active Operations, Fix #1172 --- diff --git a/src/allmydata/immutable/downloader/status.py b/src/allmydata/immutable/downloader/status.py index 3970ca17..82ca6b4c 100644 --- a/src/allmydata/immutable/downloader/status.py +++ b/src/allmydata/immutable/downloader/status.py @@ -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): diff --git a/src/allmydata/test/test_download.py b/src/allmydata/test/test_download.py index 40f0d62c..373aff58 100644 --- a/src/allmydata/test/test_download.py +++ b/src/allmydata/test/test_download.py @@ -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