'Test that client retransmits failed messages.'

def testClientRetransmission(self):

    fail = True
    num_messages = 10
    def FlakyServer(url=None, **kwargs):
        if ((not fail) or ('server.pem' in url)):
            return self.UrlMock(num_messages=num_messages, url=url, **kwargs)
        raise MakeHTTPException(500)
    with utils.Stubber(requests, 'request', FlakyServer):
        self.SendToServer()
        status = self.client_communicator.RunOnce()
        self.assertEqual(status.code, 500)
        self.assertEqual(len(self.messages), 0)
        fail = False
        self.assertEqual(self.client_communicator.client_worker.InQueueSize(), 0)
        status = self.client_communicator.RunOnce()
        self.assertEqual(status.code, 200)
        self.assertEqual(self.client_communicator.client_worker.InQueueSize(), 10)
        self.CheckClientQueue()
        self.assertEqual(len(self.messages), 10)
