Commit e3c05b2e authored by Wez's avatar Wez Committed by Commit Bot

[fuchsia] Fix TestDebugListener not to hang in RunUntilNumberOfPortsIs().

Fix RunUntilNumberOfPortsIs() to execute RunLoop::Run() only once, so
that if the condition is never met then the test will fail in a timely
manner.

Change-Id: Ie766d56d532c4cc6b680ebb3a265b935fc3a9fca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898279
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarFabrice de Gans-Riberi <fdegans@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712869}
parent ce180422
......@@ -4,7 +4,9 @@
#include "fuchsia/engine/test_debug_listener.h"
#include "base/auto_reset.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
TestDebugListener::TestDebugListener() {}
......@@ -17,22 +19,29 @@ void TestDebugListener::DestroyListener(TestPerContextListener* listener) {
void TestDebugListener::AddPort(uint16_t port) {
EXPECT_EQ(debug_ports_.find(port), debug_ports_.end());
debug_ports_.insert(port);
if (run_ack_)
std::move(run_ack_).Run();
if (on_debug_ports_changed_)
on_debug_ports_changed_.Run();
}
void TestDebugListener::RemovePort(uint16_t port) {
EXPECT_EQ(debug_ports_.erase(port), 1u);
if (run_ack_)
std::move(run_ack_).Run();
if (on_debug_ports_changed_)
on_debug_ports_changed_.Run();
}
void TestDebugListener::RunUntilNumberOfPortsIs(size_t size) {
while (debug_ports_.size() != size) {
base::RunLoop run_loop;
run_ack_ = run_loop.QuitClosure();
run_loop.Run();
}
if (debug_ports_.size() == size)
return;
base::RunLoop run_loop;
base::AutoReset<base::RepeatingClosure> set_on_debug_ports_changed(
&on_debug_ports_changed_,
base::BindLambdaForTesting([this, &run_loop, size]() {
if (debug_ports_.size() == size)
run_loop.Quit();
}));
run_loop.Run();
EXPECT_EQ(debug_ports_.size(), size);
}
TestDebugListener::TestPerContextListener::TestPerContextListener(
......
......@@ -59,7 +59,7 @@ class TestDebugListener : public fuchsia::web::DevToolsListener {
base::flat_set<std::unique_ptr<TestPerContextListener>,
base::UniquePtrComparator>
per_context_listeners_;
base::OnceClosure run_ack_;
base::RepeatingClosure on_debug_ports_changed_;
DISALLOW_COPY_AND_ASSIGN(TestDebugListener);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment