'Test processing of several inbound messages.'

def testProcessMessages(self):

    flow_obj = self.FlowSetup('WorkerSendingTestFlow')
    session_id_1 = flow_obj.session_id
    flow_obj.Close()
    flow_obj = self.FlowSetup('WorkerSendingTestFlow2')
    session_id_2 = flow_obj.session_id
    flow_obj.Close()
    manager = queue_manager.QueueManager(token=self.token)
    tasks_on_client_queue = manager.Query(self.client_id.Queue(), 100)
    self.assertEqual(len(tasks_on_client_queue), 11)
    self.SendResponse(session_id_1, 'Hello1')
    self.SendResponse(session_id_2, 'Hello2')
    self.SendResponse(session_id_1, 'Hello1')
    self.SendResponse(session_id_2, 'Hello2')
    worker_obj = worker.GRRWorker(token=self.token)
    worker_obj.RunOnce()
    worker_obj.thread_pool.Join()
    RESULTS.sort()
    self.assertEqual(2, len(RESULTS))
    self.assertEqual('Hello1', RESULTS[0])
    self.assertEqual('Hello2', RESULTS[1])
    tasks_on_client_queue = manager.Query(self.client_id.Queue(), 100)
    self.assertEqual(len(tasks_on_client_queue), 9)
    outstanding_requests = list(data_store.DB.ReadRequestsAndResponses(session_id_1, token=self.token))
    self.assertEqual(len(outstanding_requests), 9)
    for (request, _) in outstanding_requests:
        self.assertNotEqual(request.request.request_id, 0)
    flow_obj = aff4.FACTORY.Open(session_id_1, token=self.token)
    self.assertTrue((flow_obj.context.state != rdf_flows.FlowContext.State.TERMINATED))
    self.assertEqual(flow_obj.context.current_state, 'Incoming')
    flow_obj = aff4.FACTORY.Open(session_id_2, token=self.token)
    self.assertTrue((flow_obj.context.state == rdf_flows.FlowContext.State.TERMINATED))
    self.assertEqual(flow_obj.context.current_state, 'End')
