'If we write some data to a TLS connection that is blocked waiting for a
renegotiation with its peer, it will pause and resume its registered
producer exactly once.'

def test_producerDuringRenegotiation(self):

    (c, ct, cp) = self.setupStreamingProducer()
    (s, st, sp) = self.setupStreamingProducer(server=True)
    self.flushTwoTLSProtocols(ct, st)
    tlsc = ct._tlsConnection
    tlsc.renegotiate()
    self.assertRaises(WantReadError, tlsc.do_handshake)
    ct._flushSendBIO()
    st.dataReceived(self.drain(ct.transport))
    payload = 'payload'
    s.transport.write(payload)
    s.transport.loseConnection()
    ct.dataReceived(self.drain(st.transport))
    messageThatUnblocksTheServer = self.drain(ct.transport)
    for fragment in (messageThatUnblocksTheServer[0:1], messageThatUnblocksTheServer[1:2], messageThatUnblocksTheServer[2:]):
        st.dataReceived(fragment)
    self.assertEqual(st.transport.disconnecting, False)
    s.transport.unregisterProducer()
    self.flushTwoTLSProtocols(ct, st)
    self.assertEqual(st.transport.disconnecting, True)
    self.assertEqual(''.join(c.received), payload)
    self.assertEqual(sp.producerHistory, ['pause', 'resume'])
