Exemplo n.º 1
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")
Exemplo n.º 2
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")
Exemplo n.º 3
0
 def test_toResultError(self):
     """
     You can convert to a ResultError
     """
     w = Work("bob", "a", "1", "xxxx", [("a", "1", "xxxx", "val", "hash")])
     r = w.toResultError("the err")
     self.assertEqual(r, ResultError("bob", "a", "1", "xxxx", "the err", [("a", "1", "xxxx", "hash")]))
Exemplo n.º 4
0
 def test_toResult(self):
     """
     You can easily convert to a Result
     """
     w = Work("bob", "a", "1", "xxxx", [("a", "1", "xxxx", "val", "hash")])
     r = w.toResult("the result")
     self.assertEqual(r, Result("bob", "a", "1", "xxxx", "the result", [("a", "1", "xxxx", "hash")]))
Exemplo n.º 5
0
 def test_workReceived(self):
     """
     Should run the work in a thread
     """
     receiver = FakeReceiver([IResult])
     
     w = ThreadedWorker()
     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'),
     ])
     yield w.workReceived(work)
     receiver.receive.assert_called_once_with(work.toResult('bigfish'))
Exemplo n.º 6
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
Exemplo n.º 7
0
 def test_workReceived_error(self):
     """
     If there's an error doing the work, tell the result_receiver
     """
     receiver = FakeReceiver([IResultError])
     
     w = ThreadedWorker()
     ISource(w).subscribe(receiver)
     
     exc = Exception('foo')
     
     def foo(a):
         raise exc
     w.registerFunction('foo', 'v1', foo)
     
     work = Work('bob', 'foo', 'v1', 'xxxx', [
         ('a', 'v1', 'xxxx', 'big', 'BIG'),
     ])
     yield w.workReceived(work)
     receiver.receive.assert_called_once_with(work.toResultError(repr(exc)))