示例#1
0
    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)
示例#2
0
    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
示例#3
0
    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
示例#4
0
    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)
示例#5
0
 def __init__(self, **kw):
     State.__init__(self, **kw)
     # change.properties is a IProperties
     props = Properties()
     props.update(self.properties, "test")
     self.properties = props