'Check that we can efficiently destroy the flow\'s request queues.'

def testDestroyFlowStates(self):

    session_id = rdfvalue.SessionID(flow_name='test2')
    request = rdf_flows.RequestState(id=1, client_id=self.client_id, next_state='TestState', session_id=session_id)
    with queue_manager.QueueManager(token=self.token) as manager:
        manager.QueueRequest(request)
        manager.QueueResponse(rdf_flows.GrrMessage(request_id=1, response_id=1, session_id=session_id))
    all_requests = list(manager.FetchRequestsAndResponses(session_id))
    self.assertEqual(len(all_requests), 1)
    self.assertEqual(all_requests[0][0], request)
    self.assertEqual(data_store.DB.ResolveRow(session_id.Add('state'), token=self.token)[0][0], 'flow:request:00000001')
    self.assertEqual(data_store.DB.ResolveRow(session_id.Add('state/request:00000001'), token=self.token)[0][0], 'flow:response:00000001:00000001')
    with queue_manager.QueueManager(token=self.token) as manager:
        manager.DestroyFlowStates(session_id)
    all_requests = list(manager.FetchRequestsAndResponses(session_id))
    self.assertEqual(len(all_requests), 0)
    self.assertEqual(data_store.DB.ResolveRow(session_id.Add('state/request:00000001'), token=self.token), [])
    self.assertEqual(data_store.DB.ResolveRow(session_id.Add('state'), token=self.token), [])
