Commit b8cd87c4 authored by Evan Shrubsole's avatar Evan Shrubsole Committed by Commit Bot

Unflake FAWorkerTest::StartStopClearsCallback

* Refactors the callback check out of EndTest

Bug: 974078
Change-Id: Ie34b18d9ea09a0b5039acf74f32d24de98efa784
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1663415Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#670053}
parent 60d57012
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
namespace media { namespace media {
static const int kTestCallbacks = 5; static const size_t kTestCallbacks = 5;
using testing::Eq;
using testing::SizeIs;
class FakeAudioWorkerTest : public testing::Test { class FakeAudioWorkerTest : public testing::Test {
public: public:
...@@ -65,14 +68,13 @@ class FakeAudioWorkerTest : public testing::Test { ...@@ -65,14 +68,13 @@ class FakeAudioWorkerTest : public testing::Test {
base::Unretained(this), callbacks), base::Unretained(this), callbacks),
time_between_callbacks_ / 2); time_between_callbacks_ / 2);
} else { } else {
EndTest(callbacks); EndTest();
} }
} }
void EndTest(size_t callbacks) { void EndTest() {
ASSERT_TRUE(TaskRunner()->BelongsToCurrentThread()); ASSERT_TRUE(TaskRunner()->BelongsToCurrentThread());
fake_worker_.Stop(); fake_worker_.Stop();
EXPECT_LE(callbacks, callbacks_.size());
} }
scoped_refptr<base::SingleThreadTaskRunner> TaskRunner() { scoped_refptr<base::SingleThreadTaskRunner> TaskRunner() {
...@@ -96,7 +98,7 @@ TEST_F(FakeAudioWorkerTest, FakeBasicCallback) { ...@@ -96,7 +98,7 @@ TEST_F(FakeAudioWorkerTest, FakeBasicCallback) {
base::OnceClosure run_on_audio_thread = base::BindOnce( base::OnceClosure run_on_audio_thread = base::BindOnce(
&FakeAudioWorkerTest::RunOnAudioThread, base::Unretained(this)); &FakeAudioWorkerTest::RunOnAudioThread, base::Unretained(this));
base::OnceClosure end_test = base::OnceClosure end_test =
base::BindOnce(&FakeAudioWorkerTest::EndTest, base::Unretained(this), 1); base::BindOnce(&FakeAudioWorkerTest::EndTest, base::Unretained(this));
// Start() should immediately post a task to run the callback, so we // Start() should immediately post a task to run the callback, so we
// should end up with only a single callback being run. // should end up with only a single callback being run.
...@@ -108,6 +110,8 @@ TEST_F(FakeAudioWorkerTest, FakeBasicCallback) { ...@@ -108,6 +110,8 @@ TEST_F(FakeAudioWorkerTest, FakeBasicCallback) {
FROM_HERE, std::move(run_on_audio_thread), std::move(end_test)); FROM_HERE, std::move(run_on_audio_thread), std::move(end_test));
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
EXPECT_THAT(callbacks_, SizeIs(1));
} }
// Ensure the time between callbacks is correct. // Ensure the time between callbacks is correct.
...@@ -118,6 +122,8 @@ TEST_F(FakeAudioWorkerTest, TimeBetweenCallbacks) { ...@@ -118,6 +122,8 @@ TEST_F(FakeAudioWorkerTest, TimeBetweenCallbacks) {
base::Unretained(this), kTestCallbacks)); base::Unretained(this), kTestCallbacks));
scoped_task_environment_.FastForwardUntilNoTasksRemain(); scoped_task_environment_.FastForwardUntilNoTasksRemain();
EXPECT_THAT(callbacks_, SizeIs(Eq(kTestCallbacks)));
// There are only (kTestCallbacks - 1) intervals between kTestCallbacks. // There are only (kTestCallbacks - 1) intervals between kTestCallbacks.
base::TimeTicks start_time = callbacks_.front(); base::TimeTicks start_time = callbacks_.front();
std::vector<base::TimeTicks> expected_callback_times; std::vector<base::TimeTicks> expected_callback_times;
...@@ -138,21 +144,29 @@ TEST_F(FakeAudioWorkerTest, TimeBetweenCallbacks) { ...@@ -138,21 +144,29 @@ TEST_F(FakeAudioWorkerTest, TimeBetweenCallbacks) {
// Ensure Start()/Stop() on the worker doesn't generate too many callbacks. See // Ensure Start()/Stop() on the worker doesn't generate too many callbacks. See
// http://crbug.com/159049. // http://crbug.com/159049.
// Flaky test; see crbug.com/974078 TEST_F(FakeAudioWorkerTest, StartStopClearsCallbacks) {
TEST_F(FakeAudioWorkerTest, DISABLED_StartStopClearsCallbacks) { TaskRunner()->PostTask(FROM_HERE,
TaskRunner()->PostTask( base::BindOnce(&FakeAudioWorkerTest::RunOnAudioThread,
FROM_HERE, base::Unretained(this)));
base::BindOnce(&FakeAudioWorkerTest::TimeCallbacksOnAudioThread,
base::Unretained(this), kTestCallbacks));
// Issue a Stop() / Start() in between expected callbacks to maximize the // Issuing a Stop() / Start() in the middle of the callback period should not
// chance of catching the worker doing the wrong thing. // trigger a callback.
scoped_task_environment_.FastForwardBy(time_between_callbacks_ / 2); scoped_task_environment_.FastForwardBy(time_between_callbacks_ / 2);
EXPECT_THAT(callbacks_, SizeIs(1));
TaskRunner()->PostTask( TaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&FakeAudioWorkerTest::StopStartOnAudioThread, FROM_HERE, base::BindOnce(&FakeAudioWorkerTest::StopStartOnAudioThread,
base::Unretained(this))); base::Unretained(this)));
scoped_task_environment_.FastForwardBy(time_between_callbacks_);
// We expect 3 callbacks: First Start(), Second Start(), and one for the
// period. If the first callback was not cancelled, we would get 4 callbacks,
// two on the first period.
TaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&FakeAudioWorkerTest::EndTest, base::Unretained(this)));
// EndTest() will ensure the proper number of callbacks have occurred. // EndTest() will ensure the proper number of callbacks have occurred.
scoped_task_environment_.FastForwardUntilNoTasksRemain(); scoped_task_environment_.FastForwardUntilNoTasksRemain();
EXPECT_THAT(callbacks_, SizeIs(3));
} }
} // namespace media } // namespace media
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