'Test that flow priorities work on the client side.'

def testClientPrioritization(self):

    result = []
    client_mock = PriorityClientMock(result)
    client_mock = flow_test_lib.MockClient(self.client_id, client_mock, token=self.token)
    worker_mock = worker_test_lib.MockWorker(check_flow_errors=True, token=self.token)
    args = [(rdf_flows.GrrMessage.Priority.LOW_PRIORITY, 'low    priority'), (rdf_flows.GrrMessage.Priority.MEDIUM_PRIORITY, 'medium    priority'), (rdf_flows.GrrMessage.Priority.LOW_PRIORITY, 'low    priority2'), (rdf_flows.GrrMessage.Priority.HIGH_PRIORITY, 'high    priority'), (rdf_flows.GrrMessage.Priority.MEDIUM_PRIORITY, 'medium    priority2')]
    for (priority, msg) in args:
        flow.GRRFlow.StartFlow(client_id=self.client_id, flow_name='PriorityFlow', msg=msg, priority=priority, token=self.token)
    while True:
        client_processed = client_mock.Next()
        flows_run = []
        for flow_run in worker_mock.Next():
            flows_run.append(flow_run)
        if ((client_processed == 0) and (not flows_run)):
            break
    self.assertEqual(result[0:1], [u'high    priority'])
    self.assertEqual(sorted(result[1:3]), [u'medium    priority', u'medium    priority2'])
    self.assertEqual(sorted(result[3:5]), [u'low    priority', u'low    priority2'])
