Ejemplo n.º 1
0
    def test_workReceived(self):
        """
        The worker should be able to receive work and do it.
        """
        receiver = FakeReceiver([IResult], lambda x: defer.Deferred())

        w = BlockingWorker()
        ISource(w).subscribe(receiver)
        
        def foo(a, b):
            return a + b
        w.registerFunction('foo', 'version1', foo)
        
        work = Work('bob', 'foo', 'version1', 'aaaa', [
            ('a', 'v1', 'xxxx', 'big', 'BIG'),
            ('b', 'v1', 'xxxx', 'fish', 'FISH'),
        ])
        r = w.workReceived(work)
        self.assertFalse(r.called, "Should not be done, because the result "
                         "hasn't been sent, and BlockingWorker doesn't have "
                         "a queue of work to do.")
        receiver.receive.assert_called_once_with(work.toResult('bigfish'))
        receiver.results[-1].callback('foo')
        self.assertTrue(r.called, "Now that the result is confirmed sent, "
                        "the work should be considered done")
Ejemplo n.º 2
0
 def test_workReceived_error(self):
     """
     If the work results in an Exception, send an error to the error receiver
     """
     receiver = FakeReceiver([IResultError], lambda x: defer.Deferred())
     
     w = BlockingWorker()
     ISource(w).subscribe(receiver)
     
     exc = Exception('something')
     def foo(a, b):
         raise exc
     w.registerFunction('foo', 'version1', foo)
     
     work = Work('bob', 'foo', 'version1', 'aaaa', [
         ('a', 'v1', 'xxxx', '', 'BIG'),
         ('b', 'v1', 'xxxx', '', 'FISH'),
     ])
     r = w.workReceived(work)
     self.assertFalse(r.called, "Should not be done because the error hasn't"
                      " yet been received by the receiver")
     receiver.receive.assert_called_once_with(work.toResultError(repr(exc)))
     receiver.results[-1].callback('foo')
     self.assertTrue(r.called, "Now that the error was received by the "
                     "receiver, we're good")
Ejemplo n.º 3
0
 def test_receiverMapping(self):
     """
     Should receive IWork, and that's it.
     """
     worker = BlockingWorker()
     mapping = worker.receiverMapping()
     self.assertEqual(mapping[IWork], worker.workReceived)
Ejemplo n.º 4
0
    def test_workReceived_list(self):
        """
        If the inputs are a list, that should be okay too
        """
        receiver = FakeReceiver([IResult])

        w = BlockingWorker()
        ISource(w).subscribe(receiver)
        
        def foo(a, b):
            return a + b
        w.registerFunction('foo', 'version1', foo)
        
        work = Work('bob', 'foo', 'version1', 'aaaa', [
            ['a', 'v1', 'xxxx', 'big', 'BIG'],
            ['b', 'v1', 'xxxx', 'fish', 'FISH'],
        ])
        r = w.workReceived(work)
        receiver.receive.assert_called_once_with(work.toResult('bigfish'))
        return r