def testCallFolding(self): events = [] def testfn(): d = defer.Deferred() def done(): events.append('TM') d.callback(None) reactor.callLater(0, done) return d si = misc.SerializedInvocation(testfn) # run three times - the first starts testfn, the second # requires a second run, and the third is folded. si() si() si() d = self.waitForQuiet(si) def check(_): self.assertEqual(events, ['TM', 'TM']) d.addCallback(check) return d
def testCallFolding(self): events = [] def testfn(): d = defer.Deferred() def done(): events.append('TM') d.callback(None) eventually(done) return d si = misc.SerializedInvocation(testfn) # run three times - the first starts testfn, the second # requires a second run, and the third is folded. d1 = si() d2 = si() d3 = si() dq = self.waitForQuiet(si) d = defer.gatherResults([d1, d2, d3, dq]) def check(_): self.assertEqual(events, ['TM', 'TM']) d.addCallback(check) return d
def testException(self): def testfn(): d = defer.Deferred() reactor.callLater(0, d.errback, failure.Failure(RuntimeError("oh noes"))) return d si = misc.SerializedInvocation(testfn) d = si() def check(_): self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) d.addCallback(check) return d