'If a task instance\'s db state get deleted, it should fail'

def test_terminate_task(self):

    TI = models.TaskInstance
    dag = self.dagbag.dags.get('test_utils')
    task = dag.task_dict.get('sleeps_forever')
    ti = TI(task=task, execution_date=DEFAULT_DATE)
    job = jobs.LocalTaskJob(task_instance=ti, ignore_ti_state=True, executor=SequentialExecutor())
    p = multiprocessing.Process(target=job.run)
    p.start()
    sleep(5)
    settings.engine.dispose()
    session = settings.Session()
    ti.refresh_from_db(session=session)
    self.assertEqual(State.RUNNING, ti.state)
    ti = session.query(TI).filter_by(dag_id=task.dag_id, task_id=task.task_id, execution_date=DEFAULT_DATE).one()
    session.delete(ti)
    session.commit()
    p.join()
    ti.refresh_from_db(session=session)
    self.assertEqual(State.FAILED, ti.state)
    session.close()
