コード例 #1
0
 def test_empty(self):
     # test
     worker = WorkerThread()
     worker._empty = False
     worker._run()
     
     # verify
     with self.mysql.dao.create_session() as session:
         self.assertEqual(0, session.query(TaskModel).count())
     self.assertTrue(worker._empty)
     
コード例 #2
0
 def test_error(self):
     # set up
     with self.mysql.dao.create_session() as session:
         session.add(TaskModel(args=json.dumps({'a': 1, 'b': 0}), eta=datetime(2000, 1, 1), name='queue_test.worker_test.foo', queue='queue1', retries=0))
         
     # test
     worker = WorkerThread()
     worker._empty = True
     worker._run()
     
     # verify
     with self.mysql.dao.create_session() as session:
         task = session.query(TaskModel).one()
         self.assertEqual(1, task.retries)
         self.assertAlmostNow(task.eta - timedelta(minutes=1))
コード例 #3
0
 def test_success(self):
     # set up
     with self.mysql.dao.create_session() as session:
         session.add(TaskModel(args=json.dumps({'a': 1, 'b': 3}), eta=datetime(2000, 1, 1), name='worker_test.foo', queue='queue1', retries=0))
         
     # test
     worker = WorkerThread()
     worker._empty = True
     worker._run()
     
     # verify
     self.assertEqual(4, foo.result)
     with self.mysql.dao.create_session() as session:
         self.assertEqual(0, session.query(TaskModel).count())
     self.assertFalse(worker._empty)