Add a check for empty channels to ChannelManager dtor.

This is a necessary precondition for upcoming changes that will remove
calls to Invoke() that currently occur during construction/destruction
of media channel objects.

Subsequently fix RtpSenderReceiverTest to destroy channels that were
created in the constructor, in the destructor.

Bug: webrtc:11992
Change-Id: I526908d997d27495659805d84113c84c48568712
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/246680
Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35702}
diff --git a/pc/channel_manager.cc b/pc/channel_manager.cc
index b58830b..525371f 100644
--- a/pc/channel_manager.cc
+++ b/pc/channel_manager.cc
@@ -58,6 +58,8 @@
 
 ChannelManager::~ChannelManager() {
   RTC_DCHECK_RUN_ON(worker_thread_);
+  RTC_DCHECK(voice_channels_.empty());
+  RTC_DCHECK(video_channels_.empty());
 }
 
 void ChannelManager::GetSupportedAudioSendCodecs(
diff --git a/pc/rtp_sender_receiver_unittest.cc b/pc/rtp_sender_receiver_unittest.cc
index 35a0050..8043dd0 100644
--- a/pc/rtp_sender_receiver_unittest.cc
+++ b/pc/rtp_sender_receiver_unittest.cc
@@ -169,6 +169,10 @@
     local_stream_ = nullptr;
     video_track_ = nullptr;
     audio_track_ = nullptr;
+
+    channel_manager_->DestroyVoiceChannel(voice_channel_);
+    channel_manager_->DestroyVideoChannel(video_channel_);
+
     worker_thread_->Invoke<void>(RTC_FROM_HERE,
                                  [&]() { channel_manager_.reset(); });
   }