divmod-dev team mailing list archive
-
divmod-dev team
-
Mailing list archive
-
Message #00255
[Merge] lp:~exarkun/divmod.org/grabber-scheduler-usage into lp:divmod.org
Jean-Paul Calderone has proposed merging lp:~exarkun/divmod.org/grabber-scheduler-usage into lp:divmod.org.
Requested reviews:
Divmod-dev (divmod-dev)
Related bugs:
Bug #912760 in Quotient: "Unhandled GrabberConfiguration / scheduler exception"
https://bugs.launchpad.net/quotient/+bug/912760
Bug #987809 in Quotient: "Creating grabber gives AttributeError, grabber still gets created."
https://bugs.launchpad.net/quotient/+bug/987809
Bug #987820 in Quotient: "Cannot delete grabbers"
https://bugs.launchpad.net/quotient/+bug/987820
For more details, see:
https://code.launchpad.net/~exarkun/divmod.org/grabber-scheduler-usage/+merge/103982
Changed the three obvious places in `Quotient/xquotient/grabber.py` that used the long-since deleted `scheduler` attribute. Added a test for each.
--
https://code.launchpad.net/~exarkun/divmod.org/grabber-scheduler-usage/+merge/103982
Your team Divmod-dev is requested to review the proposed merge of lp:~exarkun/divmod.org/grabber-scheduler-usage into lp:divmod.org.
=== modified file 'Quotient/xquotient/grabber.py'
--- Quotient/xquotient/grabber.py 2009-07-16 00:52:55 +0000
+++ Quotient/xquotient/grabber.py 2012-04-28 14:28:21 +0000
@@ -93,6 +93,7 @@
""", default=0)
powerupNames = ["xquotient.grabber.GrabberConfiguration"]
+
class GrabberConfiguration(item.Item):
"""
Manages the creation, operation, and destruction of grabbers
@@ -124,7 +125,7 @@
config=self,
ssl=ssl)
# DO IT *NOW*
- self.scheduler.schedule(pg, extime.Time())
+ iaxiom.IScheduler(self.store).schedule(pg, extime.Time())
# OR MAYBE A LITTLE LATER
item.declareLegacyItem(GrabberConfiguration.typeName, 1, dict(
@@ -274,7 +275,7 @@
self.status = Status(store=self.store, message=u'idle')
def delete(self):
- self.config.scheduler.unscheduleAll(self)
+ iaxiom.IScheduler(self.store).unscheduleAll(self)
if self.running:
if self.protocol is not None:
self.protocol.stop()
@@ -633,7 +634,7 @@
return
self.grabber.running = False
if self._transient:
- self.grabber.config.scheduler.reschedule(
+ iaxiom.IScheduler(self.grabber.store).reschedule(
self.grabber,
self.grabber.scheduled,
extime.Time())
@@ -645,6 +646,11 @@
protocol = ControlledPOP3GrabberProtocol
def __init__(self, grabber, ssl):
+ """
+ @param grabber: The L{POP3Grabber} item driving this factory.
+
+ @param ssl: A flag indicating whether an SSL connection will be attempted.
+ """
self.grabber = grabber
self.ssl = ssl
=== modified file 'Quotient/xquotient/test/test_grabber.py'
--- Quotient/xquotient/test/test_grabber.py 2006-11-22 03:43:56 +0000
+++ Quotient/xquotient/test/test_grabber.py 2012-04-28 14:28:21 +0000
@@ -12,7 +12,7 @@
from epsilon.test import iosim
-from axiom import store
+from axiom import iaxiom, store, substore, scheduler
from xquotient import grabber, mimepart
@@ -195,7 +195,7 @@
-class POP3GrabberTestCase(unittest.TestCase):
+class POP3GrabberProtocolTestCase(unittest.TestCase):
testMessageStrings = ['First message', 'Second message', 'Last message']
@@ -360,14 +360,75 @@
+class ControlledPOP3GrabberTestCase(unittest.TestCase):
+ """
+ Tests for L{xquotient.grabber.ControlledPOP3GrabberProtocol}.
+ """
+ def test_stoppedRunningWithGrabber(self):
+ """
+ When L{ControlledPOP3GrabberProtocol.stoppedRunning} is called after a
+ transient failure, and the protocol instance has an associated grabber,
+ that grabber is rescheduled to run immediately.
+ """
+ siteStore = store.Store()
+ subStore = substore.SubStore.createNew(siteStore, ['grabber'])
+ userStore = subStore.open()
+ scheduler = iaxiom.IScheduler(userStore)
+
+ grabberItem = grabber.POP3Grabber(
+ store=userStore, username=u"alice", domain=u"example.com",
+ password=u"secret", running=True,
+ config=grabber.GrabberConfiguration(store=userStore))
+ grabberItem.scheduled = extime.Time()
+ scheduler.schedule(grabberItem, grabberItem.scheduled)
+
+ factory = grabber.POP3GrabberFactory(grabberItem, False)
+ protocol = factory.buildProtocol(None)
+ protocol.transientFailure(None)
+ protocol.stoppedRunning()
+ self.assertEqual(False, grabberItem.running)
+
+ scheduled = list(scheduler.scheduledTimes(grabberItem))
+ self.assertEqual(1, len(scheduled))
+ self.assertTrue(scheduled[0] <= extime.Time())
+
+
+
+class GrabberConfigurationTestCase(unittest.TestCase):
+ """
+ Tests for L{xquotient.grabber.GrabberConfiguration}.
+ """
+ def test_addGrabber(self):
+ """
+ L{GrabberConfiguration.addGrabber} creates a new L{POP3Grabber} item
+ scheduled to run immediately.
+ """
+ siteStore = store.Store()
+ subStore = substore.SubStore.createNew(siteStore, ['grabber'])
+ userStore = subStore.open()
+ scheduler = iaxiom.IScheduler(userStore)
+
+ config = grabber.GrabberConfiguration(store=userStore)
+ config.addGrabber(u"alice", u"secret", u"example.com", False)
+ grabberItems = list(userStore.query(grabber.POP3Grabber))
+
+ self.assertEqual(1, len(grabberItems))
+ scheduled = list(scheduler.scheduledTimes(grabberItems[0]))
+ self.assertEqual(1, len(scheduled))
+ self.assertTrue(scheduled[0] <= extime.Time())
+
+
+
class PersistentControllerTestCase(unittest.TestCase):
"""
Tests for the Axiom-y parts of L{xquotient.grabber.POP3Grabber}.
"""
def setUp(self):
self.store = store.Store()
+ self.config = grabber.GrabberConfiguration(store=self.store)
self.grabber = grabber.POP3Grabber(
store=self.store,
+ config=self.config,
username=u"testuser",
domain=u"example.com",
password=u"password")
@@ -423,3 +484,17 @@
self.grabber.shouldRetrieve([(49, '49'), (50, '50'),
(51, '51')]),
[(49, '49'), (51, '51')])
+
+
+ def test_delete(self):
+ """
+ L{POP3Grabber.delete} unschedules the grabber.
+ """
+ store = self.grabber.store
+ iaxiom.IScheduler(store).schedule(self.grabber, extime.Time())
+ self.grabber.delete()
+
+ # Can't query for the TimedEvent directly, but we know nothing *else*
+ # was scheduled either.
+ self.assertEqual(
+ [], list(store.query(scheduler.TimedEvent)))
Follow ups