コード例 #1
0
ファイル: test_conch.py プロジェクト: galaxysd/BitTorrent
 def _ebConnect(self, f):
     # probably because the server wasn't listening in time
     # but who knows, just try again
     log.msg('ERROR CONNECTING TO %s' % self.port)
     log.err(f)
     log.flushErrors()
     reactor.callLater(1, self._connect)
コード例 #2
0
 def openFailed(self, reason):
     """
     good .... good
     """
     log.msg('unknown open failed')
     log.flushErrors()
     self.conn.addResult()
コード例 #3
0
ファイル: testsuite.py プロジェクト: offlinehacker/flumotion
 def _flushErrors(self, *types):
     # This bit about log flushing seems to be necessary with twisted < 2.5.
     try:
         self.flushLoggedErrors(*types)
     except AttributeError:
         from twisted.python import log as tlog
         tlog.flushErrors(*types)
コード例 #4
0
    def testRefusedAnonymousClientConnection(self):
        onServerLost = defer.Deferred()
        onClientLost = defer.Deferred()
        self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=True, caCerts=[self.sCert], requireCertificate=True),
                      sslverify.OpenSSLCertificateOptions(requireCertificate=False),
                      onServerLost=onServerLost,
                      onClientLost=onClientLost)

        d = defer.DeferredList([onClientLost, onServerLost], consumeErrors=True)


        def afterLost(((cSuccess, cResult), (sSuccess, sResult))):

            self.failIf(cSuccess)
            self.failIf(sSuccess)

            # XXX Twisted doesn't report SSL errors as SSL errors, but in the
            # future it will.

            # cResult.trap(SSL.Error)
            # sResult.trap(SSL.Error)

            # Twisted trunk will do the correct thing here, and not log any
            # errors.  Twisted 2.1 will do the wrong thing.  We're flushing
            # errors until the buildbot is updated to a reasonable facsimilie
            # of 2.2.
            log.flushErrors(SSL.Error)
コード例 #5
0
 def testLink(self):
     linkRes = self._getCmdResult('ln testLink testfile1')
     self.failIf(linkRes)
     lslRes = self._getCmdResult('ls -l testLink')
     log.flushErrors()
     self.failUnless(lslRes.startswith('l'), 'link failed')
     self.failIf(self._getCmdResult('rm testLink'))
コード例 #6
0
 def testFailedRETR(self):
     try:
         f = protocol.Factory()
         f.noisy = 0
         port = reactor.listenTCP(0, f, interface="127.0.0.1")
         portNum = port.getHost().port
         responses = ['220 ready, dude (vsFTPd 1.0.0: beat me, break me)',
                      '331 Please specify the password.',
                      '230 Login successful. Have fun.',
                      '200 Binary it is, then.',
                      '227 Entering Passive Mode (127,0,0,1,%d,%d)' %
                      (portNum >> 8, portNum & 0xff),
                      '550 Failed to open file.']
         f.buildProtocol = lambda addr: PrintLines(responses)
         client = ftp.FTPClient(passive=1)
         cc = protocol.ClientCreator(reactor, ftp.FTPClient, passive=1)
         client = wait(cc.connectTCP('127.0.0.1', portNum))
         p = protocol.Protocol()
         d = client.retrieveFile('/file/that/doesnt/exist', p)
         d.addCallback(lambda r, self=self:
                         self.fail('Callback incorrectly called: %r' % r))
         def p(failure):
             failure.trap(ftp.CommandFailed)
         d.addErrback(p)
         wait(d)
         log.flushErrors(ftp.FTPError)
     finally:
         d = port.stopListening()
         if d is not None:
             wait(d)
コード例 #7
0
 def testErrorLog(self):
     c = self.c
     defer.Deferred().addCallback(lambda x: 1/0).callback(1)
     c2 = [e for e in c if e["isError"]]
     self.assertEquals(len(c2), 2)
     c2[1]["failure"].trap(ZeroDivisionError)
     log.flushErrors(ZeroDivisionError)
コード例 #8
0
ファイル: test_log.py プロジェクト: hitzjd/Balance-Simulate
 def testErrors(self):
     for e, ig in [("hello world", "hello world"), (KeyError(), KeyError),
                   (failure.Failure(RuntimeError()), RuntimeError)]:
         log.err(e)
         i = self.catcher.pop()
         self.assertEquals(i['isError'], 1)
         log.flushErrors(ig)
コード例 #9
0
 def testReadNotificationRaises(self):
     self.f.protocol.readConnectionLost = self.aBug
     self.client.transport.loseWriteConnection()
     spinUntil(lambda :self.f.protocol.closed)
     # XXX client won't be closed?! why isn't server sending RST?
     # or maybe it is and we have a bug here.
     self.client.transport.loseConnection()
     log.flushErrors(RuntimeError)
コード例 #10
0
ファイル: test_app.py プロジェクト: pwarren/AGDeviceControl
 def testDeferredStopService(self):
     ms = app.MultiService("MultiService")
     self.s1 = StoppingService("testService", 0)
     self.s2 = StoppingService("testService2", 1)
     ms.addService(self.s1)
     ms.addService(self.s2)
     ms.stopService().addCallback(self.woohoo)
     log.flushErrors (StopError)
コード例 #11
0
 def testErrors(self):
     for e, ig in [("hello world","hello world"),
                   (KeyError(), KeyError),
                   (failure.Failure(RuntimeError()), RuntimeError)]:
         log.err(e)
         i = self.catcher.pop()
         self.assertEquals(i['isError'], 1)
         log.flushErrors(ig)
コード例 #12
0
ファイル: test_pbfailure.py プロジェクト: fxia22/ASM_xf
 def testPBFailures(self):
     auth = authorizer.DefaultAuthorizer()
     appl = app.Application("pbfailure", authorizer=auth)
     SimpleService("pbfailure",auth,appl,self).getPerspectiveNamed("guest").makeIdentity("guest")
     p = reactor.listenTCP(0, pb.BrokerFactory(pb.AuthRoot(auth)), interface="127.0.0.1")
     self.n = p.getHost()[2]
     appl.run(save=0)
     log.flushErrors(PoopError, FailError, DieError)
コード例 #13
0
 def testChAttrs(self):
    lsRes = self._getCmdResult('ls -l testfile1')
    self.failUnless(lsRes.startswith('-rw-r--r--'), lsRes)
    self.failIf(self._getCmdResult('chmod 0 testfile1'))
    lsRes = self._getCmdResult('ls -l testfile1')
    self.failUnless(lsRes.startswith('----------'), lsRes)
    self.failIf(self._getCmdResult('chmod 644 testfile1'))
    log.flushErrors()
コード例 #14
0
ファイル: test_app.py プロジェクト: pwarren/AGDeviceControl
 def testStopServiceNone(self):
     """MultiService.stopService returns Deferred when service returns None.
     """
     ms = app.MultiService("MultiService")
     self.s1 = StoppingServiceII("testService")
     ms.addService(self.s1)
     d = ms.stopService()
     d.addCallback(self.cb_nonetest)
     log.flushErrors (StopError)
コード例 #15
0
ファイル: util.py プロジェクト: pwarren/AGDeviceControl
 def do_logErrCheck(cls):
     if log._keptErrors:
         L = []
         for err in log._keptErrors:
             if isinstance(err, failure.Failure):
                 L.append(err)
             else:
                 L.append(repr(err))
         log.flushErrors()
         raise LoggedErrors(L)
コード例 #16
0
 def tearDown(self):
     try:
         self.flushLoggedErrors(errors.NotAuthenticatedError)
     except AttributeError:
         tlog.flushErrors(errors.NotAuthenticatedError)
     log._getTheFluLogObserver().clearIgnores()
     d = self.feedServer.shutdown()
     d.addCallback(lambda _: self._bouncer.stop())
     d.addCallback(lambda _: self.assertAdditionalFDsOpen(0, 'tearDown'))
     return d
コード例 #17
0
ファイル: test_xmlrpc.py プロジェクト: fxia22/ASM_xf
 def testErrors(self):
     for code, methodName in [(666, "fail"), (666, "deferFail"),
                              (12, "fault"), (23, "noSuchMethod"),
                              (17, "deferFault")]:
         l = []
         d = self.proxy().callRemote(methodName).addErrback(l.append)
         while not l:
             reactor.iterate()
         l[0].trap(xmlrpc.Fault)
         self.assertEquals(l[0].value.faultCode, code)
     log.flushErrors(RuntimeError, ValueError)
コード例 #18
0
ファイル: test_setuphelper.py プロジェクト: bne/squeal
 def testRegeneratingIt(self):
     for mod in self.removedModules:
         self.failIf(mod.__name__ in sys.modules, 'Started with %r loaded: %r' % (mod.__name__, sys.path))
     _regeneratePluginCache(['axiom', 'xmantissa'])
     log.flushErrors(ImportError) # This is necessary since there are Axiom
                                  # plugins that depend on Mantissa, so when
                                  # Axiom is installed, Mantissa-dependent
                                  # powerups are, but Mantissa isn't some
                                  # harmless tracebacks are printed.
     for mod in self.removedModules:
         self.failIf(mod.__name__ in sys.modules, 'Loaded %r: %r' % (mod.__name__, sys.path))
コード例 #19
0
    def testErrorLog(self):
        c = self.c
        defer.Deferred().addCallback(lambda x: 1/0).callback(1)
# do you think it is rad to have memory leaks glyph
##        d = defer.Deferred()
##        d.addCallback(lambda x: 1/0)
##        d.callback(1)
##        del d
        c2 = [e for e in c if e["isError"]]
        self.assertEquals(len(c2), 2)
        c2[1]["failure"].trap(ZeroDivisionError)
        log.flushErrors(ZeroDivisionError)
コード例 #20
0
ファイル: test_pb.py プロジェクト: pwarren/AGDeviceControl
 def testBadLogin(self):
     factory = pb.PBClientFactory()
     for username, password in [("nosuchuser", "pass"), ("user", "wrongpass")]:
         d = factory.login(credentials.UsernamePassword(username, password), "BRAINS!")
         c = reactor.connectTCP("127.0.0.1", self.portno, factory)
         p = unittest.deferredError(d)
         self.failUnless(p.check("twisted.cred.error.UnauthorizedLogin"))
         c.disconnect()
         reactor.iterate()
         reactor.iterate()
         reactor.iterate()
     from twisted.cred.error import UnauthorizedLogin
     log.flushErrors(UnauthorizedLogin)
コード例 #21
0
ファイル: test_setuphelper.py プロジェクト: palfrey/epsilon
 def testRegeneratingIt(self):
     for mod in self.removedModules:
         self.failIf(
             mod.__name__ in sys.modules,
             'Started with %r loaded: %r' % (mod.__name__, sys.path))
     _regeneratePluginCache(['axiom', 'xmantissa'])
     log.flushErrors(ImportError)  # This is necessary since there are Axiom
     # plugins that depend on Mantissa, so when
     # Axiom is installed, Mantissa-dependent
     # powerups are, but Mantissa isn't some
     # harmless tracebacks are printed.
     for mod in self.removedModules:
         self.failIf(mod.__name__ in sys.modules,
                     'Loaded %r: %r' % (mod.__name__, sys.path))
コード例 #22
0
 def testBrokenTimer(self):
     t = internet.TimerService(1, lambda: 1 / 0)
     t.startService()
     util.spinWhile(lambda :t._loop.running, timeout=30)
     t.stopService()
     self.assertEquals([ZeroDivisionError],
                       [o.value.__class__ for o in log.flushErrors(ZeroDivisionError)])
コード例 #23
0
ファイル: test_scheduler.py プロジェクト: calston/tums
 def later(result):
     errs = log.flushErrors(SpecialError)
     self.assertEquals(len(errs), 1)
     self.assertEquals(
         self.store.query(TimedEventFailureLog).count(), 0)
     self.failUnless(spec.procd)
     self.failIf(spec.broken)
コード例 #24
0
ファイル: test_ident.py プロジェクト: KatiaBorges/exeLearning
    def testErrors(self):
        p = TestErrorIdentServer()
        p.makeConnection(StringTransport())
        L = []
        p.sendLine = L.append

        p.exceptionType = ident.IdentError
        p.lineReceived('123, 345')
        self.assertEquals(L[0], '123, 345 : ERROR : UNKNOWN-ERROR')
        
        p.exceptionType = ident.NoUser
        p.lineReceived('432, 210')
        self.assertEquals(L[1], '432, 210 : ERROR : NO-USER')
        
        p.exceptionType = ident.InvalidPort
        p.lineReceived('987, 654')
        self.assertEquals(L[2], '987, 654 : ERROR : INVALID-PORT')
        
        p.exceptionType = ident.HiddenUser
        p.lineReceived('756, 827')
        self.assertEquals(L[3], '756, 827 : ERROR : HIDDEN-USER')
        
        p.exceptionType = NewException
        p.lineReceived('987, 789')
        self.assertEquals(L[4], '987, 789 : ERROR : UNKNOWN-ERROR')
        errs = log.flushErrors(NewException)
        self.assertEquals(len(errs), 1)
コード例 #25
0
 def testBadLogin(self):
     d = defer.succeed(None)
     for username, password in [("nosuchuser", "pass"),
                                ("user", "wrongpass")]:
         d.addCallback(self._testBadLogin_once, username, password)
     d.addBoth(lambda res: log.flushErrors(UnauthorizedLogin))
     return d
コード例 #26
0
ファイル: test_udp.py プロジェクト: galaxysd/BitTorrent
 def cbCompleted(ign):
     """
     Flush the exceptions which the reactor should have logged and make
     sure they're actually there.
     """
     errs = log.flushErrors(BadClientError)
     self.assertEquals(len(errs), 2, "Incorrectly found %d errors, expected 2" % (len(errs),))
コード例 #27
0
ファイル: test_pb.py プロジェクト: KatiaBorges/exeLearning
 def testBadLogin(self):
     d = defer.succeed(None)
     for username, password in [("nosuchuser", "pass"),
                                ("user", "wrongpass")]:
         d.addCallback(self._testBadLogin_once, username, password)
     d.addBoth(lambda res: log.flushErrors(UnauthorizedLogin))
     return d
コード例 #28
0
ファイル: test_ftp.py プロジェクト: pwarren/AGDeviceControl
    def testFailedRETR(self):
        try:
            f = protocol.Factory()
            f.noisy = 0
            port = reactor.listenTCP(0, f, interface="127.0.0.1")
            portNum = port.getHost().port
            # This test data derived from a bug report by ranty on #twisted
            responses = ['220 ready, dude (vsFTPd 1.0.0: beat me, break me)',
                         # USER anonymous
                         '331 Please specify the password.',
                         # PASS [email protected]
                         '230 Login successful. Have fun.',
                         # TYPE I
                         '200 Binary it is, then.',
                         # PASV
                         '227 Entering Passive Mode (127,0,0,1,%d,%d)' %
                         (portNum >> 8, portNum & 0xff),
                         # RETR /file/that/doesnt/exist
                         '550 Failed to open file.']
            f.buildProtocol = lambda addr: PrintLines(responses)

            client = ftp.FTPClient(passive=1)
            cc = protocol.ClientCreator(reactor, ftp.FTPClient, passive=1)
            client = wait(cc.connectTCP('127.0.0.1', portNum))
            p = protocol.Protocol()
            d = client.retrieveFile('/file/that/doesnt/exist', p)

            # This callback should not be called
            d.addCallback(lambda r, self=self:
                            self.fail('Callback incorrectly called: %r' % r))
            def p(failure):
                # Yow!  Nested DeferredLists!
                failure.trap(defer.FirstError)
                failure.value.subFailure.trap(defer.FirstError)
                subsubFailure = failure.value.subFailure.value.subFailure
                subsubFailure.trap(ftp.CommandFailed)
                # If we got through all that, we got the right failure.

            d.addErrback(p)

            wait(d)
            log.flushErrors(ftp.FTPError)
        finally:
            d = port.stopListening()
            if d is not None:
                wait(d)
コード例 #29
0
    def testFailedRETR(self):
        try:
            f = protocol.Factory()
            f.noisy = 0
            port = reactor.listenTCP(0, f, interface="127.0.0.1")
            portNum = port.getHost().port
            # This test data derived from a bug report by ranty on #twisted
            responses = [
                '220 ready, dude (vsFTPd 1.0.0: beat me, break me)',
                # USER anonymous
                '331 Please specify the password.',
                # PASS [email protected]
                '230 Login successful. Have fun.',
                # TYPE I
                '200 Binary it is, then.',
                # PASV
                '227 Entering Passive Mode (127,0,0,1,%d,%d)' %
                (portNum >> 8, portNum & 0xff),
                # RETR /file/that/doesnt/exist
                '550 Failed to open file.'
            ]
            f.buildProtocol = lambda addr: PrintLines(responses)

            client = ftp.FTPClient(passive=1)
            cc = protocol.ClientCreator(reactor, ftp.FTPClient, passive=1)
            client = wait(cc.connectTCP('127.0.0.1', portNum))
            p = protocol.Protocol()
            d = client.retrieveFile('/file/that/doesnt/exist', p)

            # This callback should not be called, because we're expecting a
            # failure.
            d.addCallback(lambda r, self=self: self.fail(
                'Callback incorrectly called: %r' % r))

            def p(failure):
                # Make sure we got the failure we were expecting.
                failure.trap(ftp.CommandFailed)

            d.addErrback(p)

            wait(d)
            log.flushErrors(ftp.FTPError)
        finally:
            d = port.stopListening()
            if d is not None:
                wait(d)
コード例 #30
0
 def testBrokenTimer(self):
     t = internet.TimerService(1, lambda: 1 / 0)
     t.startService()
     util.spinWhile(lambda: t._loop.running, timeout=30)
     t.stopService()
     self.assertEquals(
         [ZeroDivisionError],
         [o.value.__class__ for o in log.flushErrors(ZeroDivisionError)])
コード例 #31
0
ファイル: test_udp.py プロジェクト: hitzjd/Balance-Simulate
 def cbCompleted(ign):
     """
     Flush the exceptions which the reactor should have logged and make
     sure they're actually there.
     """
     errs = log.flushErrors(BadClientError)
     self.assertEquals(
         len(errs), 2,
         "Incorrectly found %d errors, expected 2" % (len(errs), ))
コード例 #32
0
ファイル: test_ftp.py プロジェクト: fxia22/ASM_xf
    def testFailedRETR(self):
        try:
            f = Factory()
            f.noisy = 0
            f.protocol = Protocol
            port = reactor.listenTCP(0, f, interface="127.0.0.1")
            n = port.getHost()[2]
            # This test data derived from a bug report by ranty on #twisted
            responses = ['220 ready, dude (vsFTPd 1.0.0: beat me, break me)',
                         # USER anonymous
                         '331 Please specify the password.',
                         # PASS [email protected]
                         '230 Login successful. Have fun.',
                         # TYPE I
                         '200 Binary it is, then.',
                         # PASV
                         '227 Entering Passive Mode (127,0,0,1,%d,%d)' %
                         (n>>8, n&0xff),
                         # RETR /file/that/doesnt/exist
                         '550 Failed to open file.']

            b = StringIOWithoutClosing()
            client = ftp.FTPClient(passive=1)
            client.makeConnection(FileWrapper(b))
            self.writeResponses(client, responses)
            p = Protocol()
            d = client.retrieveFile('/file/that/doesnt/exist', p)
            d.addCallback(lambda r, self=self:
                            self.fail('Callback incorrectly called: %r' % r))
            d.addBoth(lambda ignored,r=reactor: r.crash())

            id = reactor.callLater(2, self.timeout)
            reactor.run()
            log.flushErrors(ftp.FTPError)
            try:
                id.cancel()
            except:
                pass
        finally:
            try:
                port.stopListening()
                reactor.iterate()
            except:
                pass
コード例 #33
0
    def testFailedRETR(self):
        try:
            f = protocol.Factory()
            f.noisy = 0
            port = reactor.listenTCP(0, f, interface="127.0.0.1")
            portNum = port.getHost().port
            # This test data derived from a bug report by ranty on #twisted
            responses = [
                "220 ready, dude (vsFTPd 1.0.0: beat me, break me)",
                # USER anonymous
                "331 Please specify the password.",
                # PASS [email protected]
                "230 Login successful. Have fun.",
                # TYPE I
                "200 Binary it is, then.",
                # PASV
                "227 Entering Passive Mode (127,0,0,1,%d,%d)" % (portNum >> 8, portNum & 0xFF),
                # RETR /file/that/doesnt/exist
                "550 Failed to open file.",
            ]
            f.buildProtocol = lambda addr: PrintLines(responses)

            client = ftp.FTPClient(passive=1)
            cc = protocol.ClientCreator(reactor, ftp.FTPClient, passive=1)
            client = wait(cc.connectTCP("127.0.0.1", portNum))
            p = protocol.Protocol()
            d = client.retrieveFile("/file/that/doesnt/exist", p)

            # This callback should not be called, because we're expecting a
            # failure.
            d.addCallback(lambda r, self=self: self.fail("Callback incorrectly called: %r" % r))

            def p(failure):
                # Make sure we got the failure we were expecting.
                failure.trap(ftp.CommandFailed)

            d.addErrback(p)

            wait(d)
            log.flushErrors(ftp.FTPError)
        finally:
            d = port.stopListening()
            if d is not None:
                wait(d)
コード例 #34
0
 def test_inputerror(self):
     p = self.runCode("import sys\nsys.stdout.write(sys.stdin.read())",
                      TestStreamer(["hello", defer.fail(ZeroDivisionError())]))
     l = []
     d = stream.readStream(p.outStream, l.append)
     d2 = p.run()
     def verify(_):
         self.assertEquals("".join(l), "hello")
         return d2
     return d.addCallback(verify).addCallback(lambda _: log.flushErrors(ZeroDivisionError))
コード例 #35
0
ファイル: test_stream.py プロジェクト: knoboo/knoboo
 def test_inputerror(self):
     p = self.runCode("import sys\nsys.stdout.write(sys.stdin.read())",
                      TestStreamer(["hello", defer.fail(ZeroDivisionError())]))
     l = []
     d = stream.readStream(p.outStream, l.append)
     d2 = p.run()
     def verify(_):
         self.assertEquals("".join(l), "hello")
         return d2
     return d.addCallback(verify).addCallback(lambda _: log.flushErrors(ZeroDivisionError))
コード例 #36
0
    def testFailedCertificateVerification(self):
        onServerLost = defer.Deferred()
        onClientLost = defer.Deferred()
        self.loopback(sslverify.OpenSSLCertificateOptions(privateKey=self.sKey, certificate=self.sCert, verify=False, requireCertificate=False),
                      sslverify.OpenSSLCertificateOptions(verify=True, requireCertificate=False, caCerts=[self.cCert]),
                      onServerLost=onServerLost,
                      onClientLost=onClientLost)

        d = defer.DeferredList([onClientLost, onServerLost], consumeErrors=True)
        def afterLost(((cSuccess, cResult), (sSuccess, sResult))):

            self.failIf(cSuccess)
            self.failIf(sSuccess)

            # Twisted trunk will do the correct thing here, and not log any
            # errors.  Twisted 2.1 will do the wrong thing.  We're flushing
            # errors until the buildbot is updated to a reasonable facsimilie
            # of 2.2.
            log.flushErrors(SSL.Error)
コード例 #37
0
 def testErrors(self):
     dl = []
     for code, methodName in [(666, "fail"), (666, "deferFail"),
                              (12, "fault"), (23, "noSuchMethod"),
                              (17, "deferFault"), (42, "SESSION_TEST")]:
         d = self.proxy().callRemote(methodName)
         d = self.assertFailure(d, xmlrpc.Fault)
         d.addCallback(lambda exc, code=code: self.assertEquals(exc.faultCode, code))
         dl.append(d)
     d = defer.DeferredList(dl, fireOnOneErrback=True)
     d.addCallback(lambda ign: log.flushErrors(TestRuntimeError, TestValueError))
     return d
コード例 #38
0
ファイル: unittest.py プロジェクト: fxia22/ASM_xf
    def cleanUp(self):
        """I clean up after the test is run. This includes making sure there
        are no pending calls lying around, garbage collecting and flushing
        errors.

        This is all to ensure that any errors caused by this tests are caught
        by this test.
        """
        self._runPhase(util.reactorCleanUp)
        if gc: gc.collect()
        for e in log.flushErrors():
            self.failures.append((self.error, e))
コード例 #39
0
ファイル: test_xmlrpc.py プロジェクト: UstadMobile/eXePUB
 def testErrors(self):
     dl = []
     for code, methodName in [(666, "fail"), (666, "deferFail"),
                              (12, "fault"), (23, "noSuchMethod"),
                              (17, "deferFault"), (42, "SESSION_TEST")]:
         d = self.proxy().callRemote(methodName)
         d = self.assertFailure(d, xmlrpc.Fault)
         d.addCallback(
             lambda exc, code=code: self.assertEquals(exc.faultCode, code))
         dl.append(d)
     d = defer.DeferredList(dl, fireOnOneErrback=True)
     d.addCallback(
         lambda ign: log.flushErrors(TestRuntimeError, TestValueError))
     return d
コード例 #40
0
ファイル: test_batch.py プロジェクト: calston/tums
    def testBrokenListener(self):
        """
        Test that if a listener's processItem method raises an
        exception, processing continues beyond that item and that an
        error marker is created for that item.
        """

        errmsg = "This reliable listener is not very reliable!"
        processedItems = []
        def listener(item):
            if item.information == 1:
                raise RuntimeError(errmsg)
            processedItems.append(item.information)

        proc = self.procType(store=self.store)
        listener = WorkListener(store=self.store, listener=listener)

        proc.addReliableListener(listener)

        # Make some work, step the processor, and fake the error handling
        # behavior the Scheduler actually provides.
        for i in range(3):
            TestWorkUnit(store=self.store, information=i)
            try:
                proc.step()
            except batch._ProcessingFailure:
                proc.timedEventErrorHandler(
                    (u"Oh crap, I do not have a TimedEvent, "
                     "I sure hope that never becomes a problem."),
                    failure.Failure())

        self.assertEquals(processedItems, [0, 2])

        errors = list(proc.getFailedItems())
        self.assertEquals(len(errors), 1)
        self.assertEquals(errors[0][0], listener)
        self.assertEquals(errors[0][1].information, 1)

        loggedErrors = log.flushErrors(RuntimeError)
        self.assertEquals(len(loggedErrors), 1)
        self.assertEquals(loggedErrors[0].getErrorMessage(), errmsg)
コード例 #41
0
ファイル: test_batch.py プロジェクト: calston/tums
    def testProcessingServiceStepsOverErrors(self):
        """
        If any processor raises an unexpected exception, the work unit which
        was being processed should be marked as having had an error and
        processing should move on to the next item.  Make sure that this
        actually happens when L{BatchProcessingService} is handling those
        errors.
        """
        BATCH_WORK_UNITS = 3

        dbdir = self.mktemp()
        st = store.Store(dbdir)
        Scheduler(store=st).installOn(st)
        source = BatchWorkSource(store=st)
        for i in range(BATCH_WORK_UNITS):
            BatchWorkItem(store=st)

        source.addReliableListener(BrokenReliableListener(store=st), iaxiom.REMOTE)
        source.addReliableListener(WorkingReliableListener(store=st), iaxiom.REMOTE)

        svc = batch.BatchProcessingService(st, iaxiom.REMOTE)

        task = svc.step()

        # Loop 6 (BATCH_WORK_UNITS * 2) times - three items times two
        # listeners, it should not take any more than six iterations to
        # completely process all work.
        for i in xrange(BATCH_WORK_UNITS * 2):
            task.next()


        self.assertEquals(
            len(log.flushErrors(BrokenException)),
            BATCH_WORK_UNITS)

        self.assertEquals(
            st.query(BatchWorkItem, BatchWorkItem.value == u"processed").count(),
            BATCH_WORK_UNITS)
コード例 #42
0
ファイル: test_log.py プロジェクト: hitzjd/Balance-Simulate
    def testErroneousErrors(self):
        L1 = []
        L2 = []
        log.addObserver(lambda events: events['isError'] or L1.append(events))
        log.addObserver(lambda events: 1 / 0)
        log.addObserver(lambda events: events['isError'] or L2.append(events))
        log.msg("Howdy, y'all.")

        excs = [f.type for f in log.flushErrors(ZeroDivisionError)]
        self.assertEquals([ZeroDivisionError], excs)

        self.assertEquals(len(L1), 2)
        self.assertEquals(len(L2), 2)

        self.assertEquals(L1[1]['message'], ("Howdy, y'all.", ))
        self.assertEquals(L2[0]['message'], ("Howdy, y'all.", ))

        # The observer has been removed, there should be no exception
        log.msg("Howdy, y'all.")

        self.assertEquals(len(L1), 3)
        self.assertEquals(len(L2), 3)
        self.assertEquals(L1[2]['message'], ("Howdy, y'all.", ))
        self.assertEquals(L2[2]['message'], ("Howdy, y'all.", ))