'pauseProducing() events can come from both the TLS transport layer and
the underlying transport. In this case, both decide to pause,
underlying first.'

def test_streamingProducerBothTransportsDecideToPause(self):

    class PausingStringTransport(StringTransport, ):
        _didPause = False
        def write(self, data):
            if ((not self._didPause) and (self.producer is not None)):
                self._didPause = True
                self.producer.pauseProducing()
            StringTransport.write(self, data)
    class TLSConnection(object, ):
        def __init__(self):
            self.l = []
        def send(self, data):
            if (not self.l):
                data = data[:(-1)]
            if (len(self.l) == 1):
                self.l.append('paused')
                raise WantReadError()
            self.l.append(data)
            return len(data)
        def set_connect_state(self):
            pass
        def do_handshake(self):
            pass
        def bio_write(self, data):
            pass
        def bio_read(self, size):
            return 'X'
        def recv(self, size):
            raise WantReadError()
    transport = PausingStringTransport()
    (clientProtocol, tlsProtocol, producer) = self.setupStreamingProducer(transport, fakeConnection=TLSConnection())
    self.assertEqual(producer.producerState, 'producing')
    clientProtocol.transport.write('hello')
    self.assertEqual(producer.producerState, 'paused')
    self.assertEqual(producer.producerHistory, ['pause'])
    tlsProtocol.transport.producer.resumeProducing()
    self.assertEqual(producer.producerState, 'producing')
    self.assertEqual(producer.producerHistory, ['pause', 'resume'])
    tlsProtocol.dataReceived('hello')
    self.assertEqual(producer.producerState, 'producing')
    self.assertEqual(producer.producerHistory, ['pause', 'resume'])
