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")
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")]))
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)))