From 341429effe26c65242bf1771ed80effa73bc1122 Mon Sep 17 00:00:00 2001 From: hai007 Date: Tue, 30 Mar 2021 15:11:57 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 365906963 --- cpp/core/internal/bwu_manager.cc | 10 ++++++---- cpp/core/internal/bwu_manager_test.cc | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cpp/core/internal/bwu_manager.cc b/cpp/core/internal/bwu_manager.cc index d9c58144..51ef1948 100644 --- a/cpp/core/internal/bwu_manager.cc +++ b/cpp/core/internal/bwu_manager.cc @@ -717,10 +717,12 @@ void BwuManager::ProcessSafeToClosePriorChannelEvent( previous_endpoint_channel->DisableEncryption(); previous_endpoint_channel->Write(parser::ForDisconnection()); - // TODO(b/172380349): Match the Java implementation with no sleep call - - // Wait for in-flight messages to reach their peers. - SystemClock::Sleep(absl::Seconds(1)); + // Attempt to read the disconnect message from the previous channel. We don't + // care whether we successfully read it or whether we get an exception here. + // The idea is just to make sure the other side has had a chance to receive + // the full SAFE_TO_CLOSE_PRIOR_CHANNEL message before we actually close the + // channel. See b/172380349 for more context. + previous_endpoint_channel->Read(); previous_endpoint_channel->Close(DisconnectionReason::UPGRADED); // Now that the old channel has been drained, we can unpause the new channel diff --git a/cpp/core/internal/bwu_manager_test.cc b/cpp/core/internal/bwu_manager_test.cc index 52ab8278..255068bf 100644 --- a/cpp/core/internal/bwu_manager_test.cc +++ b/cpp/core/internal/bwu_manager_test.cc @@ -21,6 +21,7 @@ #include "core/internal/endpoint_manager.h" #include "core/internal/mediums/mediums.h" #include "core/internal/mediums/utils.h" +#include "core/internal/offline_frames.h" #include "platform/public/system_clock.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -57,20 +58,30 @@ TEST(BwuManagerTest, CanInitiateBwu) { bwu_manager.Shutdown(); } -TEST(BwuManagerTest, CanProcessPathAvailableFrame) { +TEST(BwuManagerTest, CanProcessBandwidthUpgradeFrames) { ClientProxy client; std::string endpoint_id("EP_A"); + LocationHint location_hint = Utils::BuildLocationHint("US"); Mediums mediums; EndpointChannelManager ecm; EndpointManager em{&ecm}; BwuManager bwu_manager{mediums, em, ecm, {}, {}}; - LocationHint location_hint = Utils::BuildLocationHint("US"); - ExceptionOr wrapped_frame = parser::FromBytes( + ExceptionOr path_available_frame = parser::FromBytes( parser::ForBwuWebrtcPathAvailable("my_id", location_hint)); + bwu_manager.OnIncomingFrame(path_available_frame.result(), endpoint_id, + &client, Medium::WEB_RTC); - bwu_manager.OnIncomingFrame(wrapped_frame.result(), endpoint_id, &client, + ExceptionOr last_write_frame = + parser::FromBytes(parser::ForBwuLastWrite()); + bwu_manager.OnIncomingFrame(last_write_frame.result(), endpoint_id, &client, Medium::WEB_RTC); + + ExceptionOr safe_to_close_frame = + parser::FromBytes(parser::ForBwuSafeToClose()); + bwu_manager.OnIncomingFrame(safe_to_close_frame.result(), endpoint_id, + &client, Medium::WEB_RTC); + bwu_manager.Shutdown(); }