Exemplo n.º 1
0
 def test_on_success_eventer(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = 1
     tw.eventer = Mock()
     tw.send_event = Mock()
     tw.on_success(42)
     self.assertTrue(tw.send_event.called)
Exemplo n.º 2
0
 def test_terminate__task_started(self):
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = time.time()
     tw.worker_pid = 313
     tw.terminate(pool, signal="KILL")
     pool.terminate_job.assert_called_with(tw.worker_pid, "KILL")
Exemplo n.º 3
0
 def test_on_success_eventer(self):
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     job.time_start = 1
     job.eventer = Mock()
     job.send_event = Mock()
     job.on_success(42)
     self.assertTrue(job.send_event.called)
Exemplo n.º 4
0
 def test_on_success_acks_early(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     tw.on_success(42)
     tw._does_info = False
     tw.on_success(42)
     self.assertFalse(tw.acknowledged)
Exemplo n.º 5
0
 def test_on_success_acks_early(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     tw.on_success(42)
     tw._does_info = False
     tw.on_success(42)
     self.assertFalse(tw.acknowledged)
Exemplo n.º 6
0
 def test_terminate__task_started(self):
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = time.time()
     tw.worker_pid = 313
     tw.terminate(pool, signal="KILL")
     pool.terminate_job.assert_called_with(tw.worker_pid, "KILL")
Exemplo n.º 7
0
 def test_on_success_eventer(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     tw.eventer = Mock()
     tw.send_event = Mock()
     tw.on_success(42)
     self.assertTrue(tw.send_event.called)
Exemplo n.º 8
0
 def test_terminate__task_reserved(self):
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = None
     tw.terminate(pool, signal="KILL")
     self.assertFalse(pool.terminate_job.call_count)
     self.assertTupleEqual(tw._terminate_on_ack, (True, pool, "KILL"))
     tw.terminate(pool, signal="KILL")
Exemplo n.º 9
0
 def test_terminate__task_reserved(self):
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'})
     tw.time_start = None
     tw.terminate(pool, signal='KILL')
     self.assertFalse(pool.terminate_job.called)
     self.assertTupleEqual(tw._terminate_on_ack, (pool, 'KILL'))
     tw.terminate(pool, signal='KILL')
Exemplo n.º 10
0
 def test_on_success_acks_late(self):
     job = TaskRequest(
         self.mytask.name, uuid(), [1], {'f': 'x'}, app=self.app,
     )
     job.time_start = 1
     self.mytask.acks_late = True
     job.on_success(42)
     self.assertTrue(job.acknowledged)
Exemplo n.º 11
0
 def test_terminate__task_reserved(self):
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = None
     tw.terminate(pool, signal='KILL')
     self.assertFalse(pool.terminate_job.called)
     self.assertTupleEqual(tw._terminate_on_ack, (pool, 'KILL'))
     tw.terminate(pool, signal='KILL')
Exemplo n.º 12
0
 def test_terminate__task_reserved(self):
     pool = Mock()
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     job.time_start = None
     job.terminate(pool, signal="KILL")
     self.assertFalse(pool.terminate_job.called)
     self.assertTupleEqual(job._terminate_on_ack, (pool, "KILL"))
     job.terminate(pool, signal="KILL")
Exemplo n.º 13
0
 def test_terminate__task_reserved(self):
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = None
     tw.terminate(pool, signal="KILL")
     self.assertFalse(pool.terminate_job.call_count)
     self.assertTupleEqual(tw._terminate_on_ack, (True, pool, "KILL"))
     tw.terminate(pool, signal="KILL")
Exemplo n.º 14
0
 def test_on_success_when_failure(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     tw.on_failure = Mock()
     try:
         raise KeyError("foo")
     except Exception:
         tw.on_success(ExceptionInfo(sys.exc_info()))
         self.assertTrue(tw.on_failure.called)
Exemplo n.º 15
0
 def test_on_success_when_failure(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     tw.on_failure = Mock()
     try:
         raise KeyError("foo")
     except Exception:
         tw.on_success(ExceptionInfo())
         self.assertTrue(tw.on_failure.called)
Exemplo n.º 16
0
 def test_on_success_acks_late(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     mytask.acks_late = True
     try:
         tw.on_success(42)
         self.assertTrue(tw.acknowledged)
     finally:
         mytask.acks_late = False
Exemplo n.º 17
0
 def test_on_success_when_failure(self):
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     job.time_start = 1
     job.on_failure = Mock()
     try:
         raise KeyError("foo")
     except Exception:
         job.on_success(ExceptionInfo())
         self.assertTrue(job.on_failure.called)
Exemplo n.º 18
0
 def test_on_success_acks_late(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     mytask.acks_late = True
     try:
         tw.on_success(42)
         self.assertTrue(tw.acknowledged)
     finally:
         mytask.acks_late = False
Exemplo n.º 19
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGKILL
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     with assert_signal_called(task_revoked, sender=tw.task, terminated=True, expired=False, signum=signum):
         tw.time_start = time.time()
         tw.worker_pid = 313
         tw.terminate(pool, signal="KILL")
         pool.terminate_job.assert_called_with(tw.worker_pid, signum)
Exemplo n.º 20
0
 def test_on_success_when_failure(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = 1
     tw.on_failure = Mock()
     try:
         raise KeyError('foo')
     except Exception:
         tw.on_success(ExceptionInfo())
         self.assertTrue(tw.on_failure.called)
Exemplo n.º 21
0
 def test_on_success_acks_early(self):
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     job.time_start = 1
     job.on_success(42)
     prev, module._does_info = module._does_info, False
     try:
         job.on_success(42)
         self.assertFalse(job.acknowledged)
     finally:
         module._does_info = prev
Exemplo n.º 22
0
 def test_on_failure_acks_late(self):
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     job.time_start = 1
     self.mytask.acks_late = True
     try:
         raise KeyError("foo")
     except KeyError:
         exc_info = ExceptionInfo()
         job.on_failure(exc_info)
         self.assertTrue(job.acknowledged)
Exemplo n.º 23
0
 def test_on_success_acks_early(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'})
     tw.time_start = 1
     tw.on_success(42)
     prev, module._does_info = module._does_info, False
     try:
         tw.on_success(42)
         self.assertFalse(tw.acknowledged)
     finally:
         module._does_info = prev
Exemplo n.º 24
0
 def test_on_success_BaseException(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     with self.assertRaises(SystemExit):
         try:
             raise SystemExit()
         except SystemExit:
             tw.on_success(ExceptionInfo())
         else:
             assert False
Exemplo n.º 25
0
 def test_on_success_BaseException(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = 1
     with self.assertRaises(SystemExit):
         try:
             raise SystemExit()
         except SystemExit:
             tw.on_success(ExceptionInfo())
         else:
             assert False
Exemplo n.º 26
0
 def test_on_success_acks_early(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = 1
     tw.on_success(42)
     prev, module._does_info = module._does_info, False
     try:
         tw.on_success(42)
         self.assertFalse(tw.acknowledged)
     finally:
         module._does_info = prev
Exemplo n.º 27
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGKILL
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     with assert_signal_called(
         task_revoked, sender=job.task, request=job, terminated=True, expired=False, signum=signum
     ):
         job.time_start = time.time()
         job.worker_pid = 313
         job.terminate(pool, signal="KILL")
         pool.terminate_job.assert_called_with(job.worker_pid, signum)
Exemplo n.º 28
0
 def test_on_success_BaseException(self):
     job = TaskRequest(
         self.mytask.name, uuid(), [1], {'f': 'x'}, app=self.app,
     )
     job.time_start = 1
     with self.assertRaises(SystemExit):
         try:
             raise SystemExit()
         except SystemExit:
             job.on_success(ExceptionInfo())
         else:
             assert False
Exemplo n.º 29
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGKILL
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'})
     with assert_signal_called(task_revoked, sender=tw.task,
                               terminated=True,
                               expired=False,
                               signum=signum):
         tw.time_start = time.time()
         tw.worker_pid = 313
         tw.terminate(pool, signal='KILL')
         pool.terminate_job.assert_called_with(tw.worker_pid, signum)
Exemplo n.º 30
0
 def test_on_failure_acks_late(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     mytask.acks_late = True
     try:
         try:
             raise KeyError("foo")
         except KeyError:
             exc_info = ExceptionInfo(sys.exc_info())
             tw.on_failure(exc_info)
             self.assertTrue(tw.acknowledged)
     finally:
         mytask.acks_late = False
Exemplo n.º 31
0
 def test_on_failure_acks_late(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = 1
     mytask.acks_late = True
     try:
         try:
             raise KeyError('foo')
         except KeyError:
             exc_info = ExceptionInfo()
             tw.on_failure(exc_info)
             self.assertTrue(tw.acknowledged)
     finally:
         mytask.acks_late = False
Exemplo n.º 32
0
 def test_on_failure_acks_late(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     tw.time_start = 1
     mytask.acks_late = True
     try:
         try:
             raise KeyError('foo')
         except KeyError:
             exc_info = ExceptionInfo()
             tw.on_failure(exc_info)
             self.assertTrue(tw.acknowledged)
     finally:
         mytask.acks_late = False
Exemplo n.º 33
0
 def test_on_failure_acks_late(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {"f": "x"})
     tw.time_start = 1
     mytask.acks_late = True
     try:
         try:
             raise KeyError("foo")
         except KeyError:
             exc_info = ExceptionInfo(sys.exc_info())
             tw.on_failure(exc_info)
             self.assertTrue(tw.acknowledged)
     finally:
         mytask.acks_late = False