def test_task(self): """Verify delayed task execution""" # delay import with side effects until after setup from ploneintranet. async .celerytasks import add try: result = add.delay(2, 2, 1) except redis.exceptions.ConnectionError: self.fail("redis not available") self.assertFalse(result.ready(), "result should be delayed") time.sleep(1) if not result.ready(): time.sleep(1) # catch unexpected delay self.assertTrue(result.ready(), "result should've been ready") self.assertEqual(result.get(), 4)
def test_task(self): """Verify delayed task execution""" # delay import with side effects until after setup from ploneintranet.async.celerytasks import add try: result = add.delay(2, 2, 1) except redis.exceptions.ConnectionError: self.fail("redis not available") self.assertFalse(result.ready(), "result should be delayed") time.sleep(1) if not result.ready(): time.sleep(1) # catch unexpected delay self.assertTrue(result.ready(), "result should've been ready") self.assertEqual(result.get(), 4)
def task_roundtrip(self): try: result = add.delay(2, 2, 1) except redis.exceptions.ConnectionError: return self.fail("task", "redis not available") if result.ready(): if result.get() == 4: return self.warn("task", "runs sync (output OK).") else: return self.fail("task", "runs sync (invalid)") i = 0 while i < 5: time.sleep(1) i += 1 if result.ready(): break if not result.ready(): return self.fail("task", "no result after %s seconds" % i) else: return self.ok("task", "completed asynchronously.")