def test_powerdown(self): """ The L{Scheduler} created by the stub is powered down by the upgrade and adapting the L{Store} to L{IScheduler} succeeds with an instance of L{_SiteScheduler}. """ scheduler = self.store.findUnique(Scheduler) self.assertEquals(list(self.store.interfacesFor(scheduler)), []) self.assertIsInstance(IScheduler(self.store), _SiteScheduler)
def setUp(self): """ Create a store with a scheduler installed on it and hook the C{now} and C{callLater} methods of that scheduler so their behavior can be controlled by these tests. """ self.calls = [] self.store = Store(filepath.FilePath(self.mktemp())) self.siteScheduler = IScheduler(self.store) self.siteScheduler.callLater = self._callLater
def _schedule(self, when): """ Ensure that this hook is scheduled to run at or before C{when}. """ sched = IScheduler(self.store) for scheduledAt in sched.scheduledTimes(self): if when < scheduledAt: sched.reschedule(self, scheduledAt, when) break else: sched.schedule(self, when)
def setUp(self): self.clock = Clock() self.dbdir = filepath.FilePath(self.mktemp()) self.store = Store(self.dbdir) self.substoreItem = SubStore.createNew(self.store, ['sub']) self.substore = self.substoreItem.open() installOn(Scheduler(store=self.store), self.store) installOn(SubScheduler(store=self.substore), self.substore) self.scheduler = IScheduler(self.store) self.subscheduler = IScheduler(self.substore) self.scheduler.callLater = self.clock.callLater self.scheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock. seconds()) self.subscheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock. seconds()) IService(self.store).startService()
def setUp(self): """ Create a store with an instance of C{self.schedulerType} in it. """ self.store = Store() self.oldScheduler = self.schedulerType(store=self.store) warnings = self.flushWarnings([self.setUp]) self.assertEquals(len(warnings), 1) self.assertEquals(warnings[0]['category'], PendingDeprecationWarning) self.assertEquals( warnings[0]['message'], self.schedulerType.__name__ + " is deprecated since Axiom 0.5.32. " "Just adapt stores to IScheduler.") self.scheduler = IScheduler(self.store)
def test_powerdown(self): """ The L{SubScheduler} created by the stub is powered down by the upgrade and adapting the L{Store} to L{IScheduler} succeeds with a L{_UserScheduler}. """ scheduler = self.store.findUnique(SubScheduler) self.assertEquals(list(self.store.interfacesFor(scheduler)), []) # Slothfully grant this test store the appearance of being a user # store. self.store.parent = self.store self.assertIsInstance(IScheduler(self.store), _UserScheduler)
def test_unscheduling(self): """ Test the unscheduleFirst method of the scheduler. """ sch = IScheduler(self.store) t1 = TestEvent(testCase=self, name=u't1', store=self.store) t2 = TestEvent(testCase=self, name=u't2', store=self.store, runAgain=None) sch.schedule(t1, self.now() + timedelta(seconds=1)) sch.schedule(t2, self.now() + timedelta(seconds=2)) sch.unscheduleFirst(t1) self.clock.advance(3) self.assertEquals(t1.runCount, 0) self.assertEquals(t2.runCount, 1)
def setUp(self): """ Create a site store for the substore which will contain the IScheduler being tested. Start its IService so any scheduled events will run. """ self.storePath = filepath.FilePath(self.mktemp()) self.siteStore = Store(self.storePath) super(SubSchedulerTests, self).setUp() substoreItem = SubStore.createNew(self.siteStore, ['scheduler_test']) self.substore = substoreItem.open() self.scheduler = scheduler = IScheduler(self.substore) self.stubTime(scheduler) self.store = self.substore
def test_inspection(self): """ Test that the L{scheduledTimes} method returns an iterable of all the times at which a particular item is scheduled to run. """ now = self.now() + timedelta(seconds=1) off = timedelta(seconds=3) sch = IScheduler(self.store) runnable = TestEvent(store=self.store, name=u'Only event') sch.schedule(runnable, now) sch.schedule(runnable, now + off) sch.schedule(runnable, now + off + off) self.assertEquals(list(sch.scheduledTimes(runnable)), [now, now + off, now + off + off])
def test_scheduledTimesDuringRun(self): """ L{Scheduler.scheduledTimes} should not include scheduled times that have already triggered. """ futureTimes = [] scheduler = IScheduler(self.store) runner = HookRunner(store=self.store, hook=lambda self: futureTimes.append( list(scheduler.scheduledTimes(self)))) then = self.now() + timedelta(seconds=1) scheduler.schedule(runner, self.now()) scheduler.schedule(runner, then) self.clock.advance(1) self.assertEquals(futureTimes, [[then], []])
def setUp(self): self.store = store.Store() self.composer = MockComposer(store=self.store) self.composer.log = [] self.scheduler = IScheduler(self.store) messageData = DummyMessageImplementation(store=self.store) self.message = exmess.Message.createDraft(self.store, messageData, u'test') self.delivery = smtpout.MessageDelivery(composer=self.composer, message=self.message, store=self.store) self.fromAddress = smtpout.FromAddress(store=self.store, smtpHost=u'example.org', smtpUsername=u'radix', smtpPassword=u'secret', address=u'radix@example') self.fromAddress.setAsDefault()
def testBasicScheduledError(self): S = IScheduler(self.store) S.schedule(NotActuallyRunnable(store=self.store), self.now()) te = TestEvent(store=self.store, testCase=self, name=u't1', runAgain=None) S.schedule(te, self.now() + timedelta(seconds=1)) self.assertEquals( self.store.query(TimedEventFailureLog).count(), 0) self.clock.advance(3) self.assertEquals(te.runCount, 1) errs = self.flushLoggedErrors(AttributeError) self.assertEquals(len(errs), 1) self.assertEquals(self.store.query(TimedEventFailureLog).count(), 1)
def _doTestScheduler(self, s): # create 3 timed events. the first one fires. the second one fires, # then reschedules itself. the third one should never fire because the # reactor is shut down first. assert that the first and second fire # only once, and that the third never fires. d = Deferred() interval = 30 t1 = TestEvent(testCase=self, name=u't1', store=s, maxRunCount=1, runAgain=None, deferred=d) t2 = TestEvent(testCase=self, name=u't2', store=s, maxRunCount=2, runAgain=interval, deferred=d, winner=True) t3 = TestEvent(testCase=self, name=u't3', store=s, maxRunCount=0, runAgain=None, deferred=d) now = Time() self.ts = [t1, t2, t3] S = IScheduler(s) # Schedule them out of order to make sure behavior doesn't # depend on tasks arriving in soonest-to-latest order. S.schedule(t2, now + timedelta(milliseconds=interval * 2)) S.schedule(t1, now + timedelta(milliseconds=interval * 1)) S.schedule(t3, now + timedelta(milliseconds=interval * 100)) return d
def testScheduledErrorWithHandler(self): S = IScheduler(self.store) spec = SpecialErrorHandler(store=self.store) S.schedule(spec, self.now()) te = TestEvent(store=self.store, testCase=self, name=u't1', runAgain=None) S.schedule(te, self.now() + timedelta(seconds=1)) self.assertEquals( self.store.query(TimedEventFailureLog).count(), 0) self.clock.advance(3) self.assertEquals(te.runCount, 1) errs = self.flushLoggedErrors(SpecialError) self.assertEquals(len(errs), 1) self.assertEquals(self.store.query(TimedEventFailureLog).count(), 0) self.failUnless(spec.procd) self.failIf(spec.broken)
def test_deletedRunnable(self): """ Verify that if a scheduled item is deleted, L{TimedEvent.invokeRunnable} just deletes the L{TimedEvent} without raising an exception. """ now = self.now() scheduler = IScheduler(self.store) runnable = TestEvent(store=self.store, name=u'Only event') scheduler.schedule(runnable, now) runnable.deleteFromStore() # Invoke it manually to avoid timing complexity. timedEvent = self.store.findUnique(TimedEvent, TimedEvent.runnable == runnable) timedEvent.invokeRunnable() self.assertEqual( self.store.findUnique(TimedEvent, TimedEvent.runnable == runnable, default=None), None)
def testBasicScheduledError(self): S = IScheduler(self.store) now = Time() S.schedule(NotActuallyRunnable(store=self.store), now) d = Deferred() te = TestEvent(store=self.store, testCase=self, name=u't1', maxRunCount=1, runAgain=None, winner=True, deferred=d) self.te = te # don't gc the deferred now2 = Time() S.schedule(te, now2) self.assertEquals(self.store.query(TimedEventFailureLog).count(), 0) def later(result): errs = log.flushErrors(AttributeError) self.assertEquals(len(errs), 1) self.assertEquals( self.store.query(TimedEventFailureLog).count(), 1) return d.addCallback(later)
def get(self): return getattr(IScheduler(self.store), name)
def subUpgraded(ignored): scheduler = sub.findUnique(SubScheduler) self.assertEqual(list(sub.interfacesFor(scheduler)), []) self.assertIsInstance(IScheduler(sub), _UserScheduler)
def test_implementsSchedulerInterface(self): """ Verify that IScheduler is declared as implemented. """ self.failUnless(IScheduler.providedBy(IScheduler(self.store)))
def setUp(self): self.clock = Clock() scheduler = IScheduler(self.siteStore) self.stubTime(scheduler) IService(self.siteStore).startService()
def run(self): """ Tick our C{loginAccount}'s L{SubScheduler}. """ IScheduler(self.loginAccount).tick()
def run(self): scheduler = IScheduler(self.store) scheduler.schedule(self, self.rescheduleFor) self.ran = True
def __init__(self, store): self._store = store self._scheduler = IScheduler(self._store) self._chain = japaneseChain() Resource.__init__(self)
def schedule(self): IScheduler(self.store).schedule(self, self.scheduled)
def set(self, value): setattr(IScheduler(self.store), name, value)
def now(self): """ Report the current time, as reported by the parent's scheduler. """ return IScheduler(self.store.parent).now()
def run(self): """ Tick our C{subStore}'s L{SubScheduler}. """ IScheduler(self.subStore).tick()