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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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, )
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)
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)
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)
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)
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')
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, )
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)
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')