DownloadStatus: show active immutable downloads in Active Operations, Fix #1172
authorfrancois <francois@ctrlaltdel.ch>
Thu, 2 Sep 2010 10:17:28 +0000 (03:17 -0700)
committerfrancois <francois@ctrlaltdel.ch>
Thu, 2 Sep 2010 10:17:28 +0000 (03:17 -0700)
src/allmydata/immutable/downloader/status.py
src/allmydata/test/test_download.py

index 3970ca17b11c9a3700921f4dd97f00b5734be067..82ca6b4c18041de322fb95760745f974f3687399 100644 (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):
index 40f0d62c07f08597e8f13221f5985d10a0f923a4..373aff58dbe3f46ad3c1e940b0d8ec6c43ce9192 100644 (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