old_contents: import asyncio
  from unittest import TestCase
  
  from aiortc.codecs import PCMU_CODEC
  from aiortc.exceptions import InvalidStateError
  from aiortc.mediastreams import AudioFrame
  from aiortc.rtcrtpparameters import RTCRtpParameters
  from aiortc.rtcrtpreceiver import RemoteStreamTrack, RTCRtpReceiver
  from aiortc.rtp import RtcpPacket, RtpPacket
  
  from .utils import dummy_dtls_transport_pair, load, run
  
  
  class ClosedDtlsTransport:
      state = 'closed'
  
  
  class RTCRtpReceiverTest(TestCase):
      def test_connection_error(self):
          """
          Close the underlying transport before the receiver.
          """
          transport, _ = dummy_dtls_transport_pair()
  
          receiver = RTCRtpReceiver('audio', transport)
          self.assertEqual(receiver.transport, transport)
  
          run(receiver.receive(RTCRtpParameters(codecs=[PCMU_CODEC])))
  
          run(transport.close())
  
      def test_rtp_and_rtcp(self):
          transport, remote = dummy_dtls_transport_pair()
  
          receiver = RTCRtpReceiver('audio', transport)
          self.assertEqual(receiver.transport, transport)
  
          receiver._track = RemoteStreamTrack(kind='audio')
          run(receiver.receive(RTCRtpParameters(codecs=[PCMU_CODEC])))
  
          # receive RTP
          packet = RtpPacket.parse(load('rtp.bin'))
          run(receiver._handle_rtp_packet(packet))
  
          # receive RTCP
          for packet in RtcpPacket.parse(load('rtcp_sr.bin')):
              run(receiver._handle_rtcp_packet(packet))
          self.assertEqual(sorted(receiver._stats.keys()), [
              'remote-inbound-rtp',
              'remote-outbound-rtp'
          ])
  
          # check remote track
          frame = run(receiver._track.recv())
          self.assertTrue(isinstance(frame, AudioFrame))
  
          # shutdown
          run(receiver.stop())
          run(asyncio.sleep(0))
  
      def test_invalid_dtls_transport_state(self):
          dtlsTransport = ClosedDtlsTransport()
          with self.assertRaises(InvalidStateError):
              RTCRtpReceiver('audio', dtlsTransport)
  
new_contents: from unittest import TestCase
  
  from aiortc.codecs import PCMU_CODEC
  from aiortc.exceptions import InvalidStateError
  from aiortc.mediastreams import AudioFrame
  from aiortc.rtcrtpparameters import RTCRtpParameters
  from aiortc.rtcrtpreceiver import RemoteStreamTrack, RTCRtpReceiver
  from aiortc.rtp import RtcpPacket, RtpPacket
  
  from .utils import dummy_dtls_transport_pair, load, run
  
  
  class ClosedDtlsTransport:
      state = 'closed'
  
  
  class RTCRtpReceiverTest(TestCase):
      def test_connection_error(self):
          """
          Close the underlying transport before the receiver.
          """
          transport, _ = dummy_dtls_transport_pair()
  
          receiver = RTCRtpReceiver('audio', transport)
          self.assertEqual(receiver.transport, transport)
  
          run(receiver.receive(RTCRtpParameters(codecs=[PCMU_CODEC])))
  
          run(transport.close())
  
      def test_rtp_and_rtcp(self):
          transport, remote = dummy_dtls_transport_pair()
  
          receiver = RTCRtpReceiver('audio', transport)
          self.assertEqual(receiver.transport, transport)
  
          receiver._track = RemoteStreamTrack(kind='audio')
          run(receiver.receive(RTCRtpParameters(codecs=[PCMU_CODEC])))
  
          # receive RTP
          packet = RtpPacket.parse(load('rtp.bin'))
          run(receiver._handle_rtp_packet(packet))
  
          # receive RTCP
          for packet in RtcpPacket.parse(load('rtcp_sr.bin')):
              run(receiver._handle_rtcp_packet(packet))
          self.assertEqual(sorted(receiver._stats.keys()), [
              'remote-inbound-rtp',
              'remote-outbound-rtp'
          ])
  
          # check remote track
          frame = run(receiver._track.recv())
          self.assertTrue(isinstance(frame, AudioFrame))
  
          # shutdown
          run(receiver.stop())
  
      def test_invalid_dtls_transport_state(self):
          dtlsTransport = ClosedDtlsTransport()
          with self.assertRaises(InvalidStateError):
              RTCRtpReceiver('audio', dtlsTransport)
  
subject: remove useless sleep