Skip to content

Commit

Permalink
[Chromecast] Fix a race condition in AudioSocketBrokerTest.
Browse files Browse the repository at this point in the history
Server socket may have not been setup yet when a connection request is
initiated because the setup logic is on the IO thread.

Bug: 1276106
Test: cast_shell_unittests
Change-Id: Ice0ae8c4573ce87c7b03d91d49309bd4164630b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3359930
Reviewed-by: Kenneth MacKay <kmackay@chromium.org>
Commit-Queue: Junbo Ke <juke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#954365}
  • Loading branch information
Junbo Ke authored and Chromium LUCI CQ committed Dec 28, 2021
1 parent 7965be8 commit f98626e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions chromecast/browser/audio_socket_broker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/posix/eintr_wrapper.h"
#include "base/posix/unix_domain_socket.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "chromecast/net/socket_util.h"
#include "content/public/test/test_content_client_initializer.h"
Expand Down Expand Up @@ -63,16 +64,18 @@ class AudioSocketBrokerTest : public content::RenderViewHostTestHarness {
}

void SetupServerSocket() {
base::WaitableEvent server_setup_finished;
io_thread_ = std::make_unique<base::Thread>("test_io_thread");
io_thread_->StartWithOptions(
base::Thread::Options(base::MessagePumpType::IO, 0));
io_thread_->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&AudioSocketBrokerTest::SetupServerSocketOnIoThread,
base::Unretained(this)));
base::Unretained(this), &server_setup_finished));
server_setup_finished.Wait();
}

void SetupServerSocketOnIoThread() {
void SetupServerSocketOnIoThread(base::WaitableEvent* server_setup_finished) {
auto unix_socket = std::make_unique<net::UnixDomainServerSocket>(
base::BindRepeating(
[](const net::UnixDomainServerSocket::Credentials&) {
Expand All @@ -87,6 +90,7 @@ class AudioSocketBrokerTest : public content::RenderViewHostTestHarness {
&accepted_descriptor_,
base::BindRepeating(&AudioSocketBrokerTest::OnAccept,
base::Unretained(this)));
server_setup_finished->Signal();
}

void OnAccept(int result) {
Expand Down

0 comments on commit f98626e

Please sign in to comment.