'Draining the flow requests and preparing messages.'

def testDrainUpdateSessionRequestStates(self):

    flow_obj = self.FlowSetup('SendingTestFlow')
    session_id = flow_obj.session_id
    manager = queue_manager.QueueManager(token=self.token)
    tasks = manager.Query(self.client_id, 100)
    self.assertEqual(len(tasks), 10)
    requests_by_id = {}
    for (request, _) in data_store.DB.ReadRequestsAndResponses(session_id, token=self.token):
        requests_by_id[request.id] = request
    for task in tasks:
        request_id = task.request_id
        request = requests_by_id[request_id]
        self.assertEqual(request.request.task_id, task.task_id)
    response = rdf_flows.MessageList()
    response.job = self.server.DrainTaskSchedulerQueueForClient(self.client_id, 5)
    self.assertEqual(len(response.job), 5)
    for i in range(4):
        self.assertEqual(response.job[i].session_id, session_id)
        self.assertEqual(response.job[i].name, 'Test')
