def test_multi_sequential(self): state = State(in_proc=False, entries=0) for i in range(10): def cb(): state.entries += 1 assert not state.in_proc state.in_proc = True d = defer.Deferred() def finish(): assert state.in_proc state.in_proc = False d.callback(None) reactor.callLater(0, finish) return d self.loop.add(cb) self.loop.trigger() def check(res): self.assertEqual(state.entries, 10) return self.whenQuiet(check)
def make_cb(self, tag, selfTrigger=None): state = State(triggerCount=selfTrigger) def cb(): if selfTrigger: self.results.append("%s-%d" % (tag, state.triggerCount)) state.triggerCount -= 1 if state.triggerCount > 0: self.loop.trigger() else: self.results.append(tag) return cb
def test_sleep(self): reactor = self.loop._reactor = task.Clock() eventual._setReactor(reactor) state = State(count=5) def proc(): self.results.append(reactor.seconds()) state.count -= 1 if state.count: return defer.succeed(reactor.seconds() + 10.0) self.loop.add(proc) self.loop.trigger() def check(ign): reactor.pump((0, ) + (1, ) * 50) # run for 50 fake seconds self.assertEqual(self.results, [0.0, 10.0, 20.0, 30.0, 40.0]) d = eventual.flushEventualQueue() d.addCallback(check) return d
def test_mergeTriggers(self): state = State(count=4) def make_proc( ): # without this, proc will only be added to the loop once def proc(): self.results.append("p") if state.count > 0: self.results.append("t") self.loop.trigger() state.count -= 1 return proc self.loop.add(make_proc()) self.loop.add(make_proc()) self.loop.trigger() # there should be four triggers, and three runs of the loop def check(res): self.assertEqual( res, ['p', 't', 'p', 't', 'p', 't', 'p', 't', 'p', 'p']) return self.whenQuiet(check)
def __init__(self, **kw): State.__init__(self, **kw) # change.properties is a IProperties props = Properties() props.update(self.properties, "test") self.properties = props