diff --git a/src/wormhole/server/rendezvous.py b/src/wormhole/server/rendezvous.py index 8633df9..db215d7 100644 --- a/src/wormhole/server/rendezvous.py +++ b/src/wormhole/server/rendezvous.py @@ -534,7 +534,7 @@ class Rendezvous(service.MultiService): service.MultiService.__init__(self) self._db = db self._welcome = welcome - self._blur_usage = None + self._blur_usage = blur_usage log_requests = blur_usage is None self._log_requests = log_requests self._apps = {} diff --git a/src/wormhole/test/test_server.py b/src/wormhole/test/test_server.py index 7e6238a..b8e3009 100644 --- a/src/wormhole/test/test_server.py +++ b/src/wormhole/test/test_server.py @@ -953,6 +953,40 @@ class Summary(unittest.TestCase): self.assertEqual(summ(2, second=3, pruned=True), Usage(1, 2, 4, u"pruney")) + def test_blur(self): + db = get_db(":memory:") + rv = rendezvous.Rendezvous(db, None, 3600) + APPID = u"appid" + app = rv.get_app(APPID) + app.claim_nameplate(u"npid", u"side1", 10) # start time is 10 + rv.prune(now=123, old=50) + # start time should be rounded to top of the hour (blur_usage=3600) + row = db.execute("SELECT * FROM `nameplate_usage`").fetchone() + self.assertEqual(row["started"], 0) + + app = rv.get_app(APPID) + app.open_mailbox(u"mbid", u"side1", 20) # start time is 20 + rv.prune(now=123, old=50) + row = db.execute("SELECT * FROM `mailbox_usage`").fetchone() + self.assertEqual(row["started"], 0) + + def test_no_blur(self): + db = get_db(":memory:") + rv = rendezvous.Rendezvous(db, None, None) + APPID = u"appid" + app = rv.get_app(APPID) + app.claim_nameplate(u"npid", u"side1", 10) # start time is 10 + rv.prune(now=123, old=50) + row = db.execute("SELECT * FROM `nameplate_usage`").fetchone() + self.assertEqual(row["started"], 10) + + app = rv.get_app(APPID) + app.open_mailbox(u"mbid", u"side1", 20) # start time is 20 + rv.prune(now=123, old=50) + row = db.execute("SELECT * FROM `mailbox_usage`").fetchone() + self.assertEqual(row["started"], 20) + + class Accumulator(protocol.Protocol): def __init__(self): self.data = b""