Exemplo n.º 1
0
 def test_revoked(self):
     job = self.xRequest()
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=False, expired=False, signum=None):
         revoked.add(job.id)
         self.assertTrue(job.revoked())
         self.assertTrue(job._already_revoked)
         self.assertTrue(job.acknowledged)
Exemplo n.º 2
0
 def test_revoked(self):
     job = TaskRequest(self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app)
     with assert_signal_called(
         task_revoked, sender=job.task, request=job, terminated=False, expired=False, signum=None
     ):
         revoked.add(job.id)
         self.assertTrue(job.revoked())
         self.assertTrue(job._already_revoked)
         self.assertTrue(job.acknowledged)
Exemplo n.º 3
0
 def test_revoked(self):
     job = self.xRequest()
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=False, expired=False, signum=None):
         revoked.add(job.id)
         self.assertTrue(job.revoked())
         self.assertTrue(job._already_revoked)
         self.assertTrue(job.acknowledged)
Exemplo n.º 4
0
 def test_revoked_expires_expired(self):
     job = TaskRequest(
         self.mytask.name, uuid(), [1], {"f": "x"}, app=self.app, expires=datetime.utcnow() - timedelta(days=1)
     )
     with assert_signal_called(
         task_revoked, sender=job.task, request=job, terminated=False, expired=True, signum=None
     ):
         job.revoked()
         self.assertIn(job.id, revoked)
         self.assertEqual(self.mytask.backend.get_status(job.id), states.REVOKED)
Exemplo n.º 5
0
 def test_revoked(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'})
     with assert_signal_called(task_revoked, sender=tw.task,
                               terminated=False,
                               expired=False,
                               signum=None):
         revoked.add(tw.id)
         self.assertTrue(tw.revoked())
         self.assertTrue(tw._already_revoked)
         self.assertTrue(tw.acknowledged)
Exemplo n.º 6
0
 def test_on_accepted_terminates(self):
     signum = signal.SIGKILL
     pool = Mock()
     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.terminate(pool, signal="KILL")
         self.assertFalse(pool.terminate_job.call_count)
         job.on_accepted(pid=314, time_accepted=time.time())
         pool.terminate_job.assert_called_with(314, signum)
Exemplo n.º 7
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.º 8
0
 def test_on_accepted_terminates(self):
     signum = signal.SIGTERM
     pool = Mock()
     job = self.xRequest()
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=True, expired=False, signum=signum):
         job.terminate(pool, signal='TERM')
         self.assertFalse(pool.terminate_job.call_count)
         job.on_accepted(pid=314, time_accepted=monotonic())
         pool.terminate_job.assert_called_with(314, signum)
Exemplo n.º 9
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGTERM
     job = self.get_request(self.mytask.s(1, f='x'))
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=True, expired=False, signum=signum):
         job.time_start = monotonic()
         job.worker_pid = 313
         job.terminate(pool, signal='TERM')
         pool.terminate_job.assert_called_with(job.worker_pid, signum)
Exemplo n.º 10
0
 def test_revoked_expires_expired(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'},
                      expires=datetime.utcnow() - timedelta(days=1))
     with assert_signal_called(task_revoked, sender=tw.task,
                               terminated=False,
                               expired=True,
                               signum=None):
         tw.revoked()
         self.assertIn(tw.id, revoked)
         self.assertEqual(mytask.backend.get_status(tw.id),
                          states.REVOKED)
Exemplo n.º 11
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGKILL
     job = Request({"task": self.mytask.name, "id": uuid(), "args": [1], "kwrgs": {"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 = monotonic()
         job.worker_pid = 313
         job.terminate(pool, signal="KILL")
         pool.terminate_job.assert_called_with(job.worker_pid, signum)
Exemplo n.º 12
0
 def test_revoked(self):
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     with assert_signal_called(task_revoked,
                               sender=tw.task,
                               terminated=False,
                               expired=False,
                               signum=None):
         revoked.add(tw.id)
         self.assertTrue(tw.revoked())
         self.assertTrue(tw._already_revoked)
         self.assertTrue(tw.acknowledged)
Exemplo n.º 13
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGTERM
     job = self.get_request(self.mytask.s(1, f='x'))
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=True, expired=False, signum=signum):
         job.time_start = monotonic()
         job.worker_pid = 313
         job.terminate(pool, signal='TERM')
         pool.terminate_job.assert_called_with(job.worker_pid, signum)
Exemplo n.º 14
0
 def test_on_accepted_terminates(self):
     signum = signal.SIGTERM
     pool = Mock()
     job = self.xRequest()
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=True, expired=False, signum=signum):
         job.terminate(pool, signal='TERM')
         self.assertFalse(pool.terminate_job.call_count)
         job.on_accepted(pid=314, time_accepted=monotonic())
         pool.terminate_job.assert_called_with(314, signum)
Exemplo n.º 15
0
 def test_on_accepted_terminates(self):
     signum = signal.SIGKILL
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'})
     with assert_signal_called(task_revoked, sender=tw.task,
                               terminated=True,
                               expired=False,
                               signum=signum):
         tw.terminate(pool, signal='KILL')
         self.assertFalse(pool.terminate_job.call_count)
         tw.on_accepted(pid=314, time_accepted=time.time())
         pool.terminate_job.assert_called_with(314, signum)
Exemplo n.º 16
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.º 17
0
 def test_revoked_expires_expired(self):
     job = self.get_request(self.mytask.s(1, f='x').set(
         expires=datetime.utcnow() - timedelta(days=1)
     ))
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=False, expired=True, signum=None):
         job.revoked()
         self.assertIn(job.id, revoked)
         self.assertEqual(
             self.mytask.backend.get_status(job.id),
             states.REVOKED,
         )
Exemplo n.º 18
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGKILL
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     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.º 19
0
 def test_revoked_expires_expired(self):
     job = self.get_request(self.mytask.s(1, f='x').set(
         expires=datetime.utcnow() - timedelta(days=1)
     ))
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=False, expired=True, signum=None):
         job.revoked()
         self.assertIn(job.id, revoked)
         self.assertEqual(
             self.mytask.backend.get_status(job.id),
             states.REVOKED,
         )
Exemplo n.º 20
0
 def test_on_accepted_terminates(self):
     signum = signal.SIGKILL
     pool = Mock()
     tw = TaskRequest(mytask.name, uuid(), [1], {'f': 'x'}, app=self.app)
     with assert_signal_called(task_revoked,
                               sender=tw.task,
                               terminated=True,
                               expired=False,
                               signum=signum):
         tw.terminate(pool, signal='KILL')
         self.assertFalse(pool.terminate_job.call_count)
         tw.on_accepted(pid=314, time_accepted=time.time())
         pool.terminate_job.assert_called_with(314, signum)
Exemplo n.º 21
0
 def test_revoked_expires_expired(self):
     tw = TaskRequest(mytask.name,
                      uuid(), [1], {'f': 'x'},
                      expires=datetime.utcnow() - timedelta(days=1),
                      app=self.app)
     with assert_signal_called(task_revoked,
                               sender=tw.task,
                               terminated=False,
                               expired=True,
                               signum=None):
         tw.revoked()
         self.assertIn(tw.id, revoked)
         self.assertEqual(mytask.backend.get_status(tw.id), states.REVOKED)
Exemplo n.º 22
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGTERM
     job = Request({
         'task': self.mytask.name,
         'id': uuid(),
         'args': [1],
         'kwrgs': {'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 = monotonic()
         job.worker_pid = 313
         job.terminate(pool, signal='TERM')
         pool.terminate_job.assert_called_with(job.worker_pid, signum)
Exemplo n.º 23
0
    def test_terminate__pool_ref(self):
        pool = Mock()
        signum = signal.SIGTERM
        job = self.get_request(self.mytask.s(1, f='x'))
        job._apply_result = Mock(name='_apply_result')
        with assert_signal_called(
                task_revoked, sender=job.task, request=job,
                terminated=True, expired=False, signum=signum):
            job.time_start = monotonic()
            job.worker_pid = 314
            job.terminate(pool, signal='TERM')
            job._apply_result().terminate.assert_called_with(signum)

            job._apply_result = Mock(name='_apply_result2')
            job._apply_result.return_value = None
            job.terminate(pool, signal='TERM')
Exemplo n.º 24
0
 def test_terminate__task_started(self):
     pool = Mock()
     signum = signal.SIGTERM
     job = Request({
         'task': self.mytask.name,
         'id': uuid(),
         'args': [1],
         'kwrgs': {'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 = monotonic()
         job.worker_pid = 313
         job.terminate(pool, signal='TERM')
         pool.terminate_job.assert_called_with(job.worker_pid, signum)
Exemplo n.º 25
0
 def test_revoked_expires_expired(self):
     job = Request({
         'task': self.mytask.name,
         'id': uuid(),
         'args': [1],
         'kwargs': {'f': 'x'},
         'expires': datetime.utcnow() - timedelta(days=1),
     }, app=self.app)
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=False, expired=True, signum=None):
         job.revoked()
         self.assertIn(job.id, revoked)
         self.assertEqual(
             self.mytask.backend.get_status(job.id),
             states.REVOKED,
         )
Exemplo n.º 26
0
 def test_revoked_expires_expired(self):
     job = Request(
         {
             "task": self.mytask.name,
             "id": uuid(),
             "args": [1],
             "kwargs": {"f": "x"},
             "expires": datetime.utcnow() - timedelta(days=1),
         },
         app=self.app,
     )
     with assert_signal_called(
         task_revoked, sender=job.task, request=job, terminated=False, expired=True, signum=None
     ):
         job.revoked()
         self.assertIn(job.id, revoked)
         self.assertEqual(self.mytask.backend.get_status(job.id), states.REVOKED)
Exemplo n.º 27
0
 def test_revoked_expires_expired(self):
     job = Request({
         'task': self.mytask.name,
         'id': uuid(),
         'args': [1],
         'kwargs': {'f': 'x'},
         'expires': datetime.utcnow() - timedelta(days=1),
     }, app=self.app)
     with assert_signal_called(
             task_revoked, sender=job.task, request=job,
             terminated=False, expired=True, signum=None):
         job.revoked()
         self.assertIn(job.id, revoked)
         self.assertEqual(
             self.mytask.backend.get_status(job.id),
             states.REVOKED,
         )
Exemplo n.º 28
0
    def test_terminate__pool_ref(self):
        pool = Mock()
        signum = signal.SIGTERM
        job = self.get_request(self.mytask.s(1, f='x'))
        job._apply_result = Mock(name='_apply_result')
        with assert_signal_called(task_revoked,
                                  sender=job.task,
                                  request=job,
                                  terminated=True,
                                  expired=False,
                                  signum=signum):
            job.time_start = monotonic()
            job.worker_pid = 314
            job.terminate(pool, signal='TERM')
            job._apply_result().terminate.assert_called_with(signum)

            job._apply_result = Mock(name='_apply_result2')
            job._apply_result.return_value = None
            job.terminate(pool, signal='TERM')