コード例 #1
0
    def test_callable_gets_called(self):
        bgwork = WorkQueue()
        cb = CB()
        bgwork.defer(cb)
        bgwork.perform()

        self.assertEqual(1, cb.called)
コード例 #2
0
    def test_performing_clears_deferred_jobs(self):
        bgwork = WorkQueue()
        cb = CB()
        bgwork.defer(cb)
        bgwork.perform()
        bgwork.perform()

        self.assertEqual(1, cb.called)
コード例 #3
0
    def test_deferred_bgwork_can_create_more_deferred_bgwork(self):
        bgwork = WorkQueue()
        final_cb = CB()

        @bgwork.defer
        def create_more_work():
            bgwork.defer(final_cb)

        bgwork.perform()

        self.assertEqual(1, final_cb.called)
コード例 #4
0
    def test_multiple_callables_get_called(self):
        bgwork = WorkQueue()
        cb1 = CB()
        cb2 = CB()

        bgwork.defer(cb1)
        bgwork.defer(cb2)

        bgwork.perform()

        self.assertEqual(1, cb1.called)
        self.assertEqual(1, cb2.called)
コード例 #5
0
    def test_exceptions_are_isolated(self):
        bgwork = WorkQueue()

        def fail():
            raise Exception('Just testing bgwork exceptions - not a real error.')
        after_exception = CB()

        bgwork.defer(fail)
        bgwork.defer(after_exception)

        bgwork.perform()

        self.assertEqual(1, after_exception.called)
コード例 #6
0
 def test_noop_doesnt_raise(self):
     bgwork = WorkQueue()
     bgwork.perform()