From 485bfc0fd67ef42130444622c9a5f3c18cd18a3d Mon Sep 17 00:00:00 2001 From: francois Date: Thu, 2 Sep 2010 03:17:28 -0700 Subject: [PATCH] DownloadStatus: show active immutable downloads in Active Operations, Fix #1172 --- src/allmydata/immutable/downloader/status.py | 9 ++++++++- src/allmydata/test/test_download.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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 -- 2.45.2