def test_t2_expired_when_shutdown_sent(self):
        async def mock_send_chunk(chunk):
            pass

        client_transport = DummyDtlsTransport()
        client = RTCSctpTransport(client_transport)
        client._last_received_tsn = 0
        client._send_chunk = mock_send_chunk

        chunk = ShutdownChunk()

        # fails once
        client.state = RTCSctpTransport.State.SHUTDOWN_SENT
        client._t2_start(chunk)
        client._t2_expired()
        self.assertEqual(client._t2_failures, 1)
        self.assertIsNotNone(client._t2_handle)
        self.assertEqual(client.state, RTCSctpTransport.State.SHUTDOWN_SENT)

        # fails 10 times
        client._t2_failures = 9
        client._t2_expired()
        self.assertEqual(client._t2_failures, 10)
        self.assertIsNotNone(client._t2_handle)
        self.assertEqual(client.state, RTCSctpTransport.State.SHUTDOWN_SENT)

        # fails 11 times
        client._t2_expired()
        self.assertEqual(client._t2_failures, 11)
        self.assertIsNone(client._t2_handle)
        self.assertEqual(client.state, RTCSctpTransport.State.CLOSED)
Exemple #2
0
    def test_receive_shutdown(self):
        async def mock_send_chunk(chunk):
            pass

        client_transport, _ = dummy_dtls_transport_pair()
        client = RTCSctpTransport(client_transport)
        client._last_received_tsn = 0
        client._send_chunk = mock_send_chunk
        client.state = RTCSctpTransport.State.ESTABLISHED

        # receive shutdown
        chunk = ShutdownChunk()
        chunk.cumulative_tsn = tsn_minus_one(client._last_sacked_tsn)
        run(client._receive_chunk(chunk))
        self.assertEqual(client.state,
                         RTCSctpTransport.State.SHUTDOWN_ACK_SENT)

        # receive shutdown complete
        chunk = ShutdownCompleteChunk()
        run(client._receive_chunk(chunk))
        self.assertEqual(client.state, RTCSctpTransport.State.CLOSED)