Esempio 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")
Esempio n. 2
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")]))
Esempio n. 3
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'))
Esempio 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