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

Fix PipelineIntegrationTestBase::WaitUntilEnded() to fail on error.

Previously WaitUntilEnded() would not install an on-error closure, and
so would fail to exit on pipeline errors, causing the test to hang
rather than fail.

WaitUntilEnded() now waits for either end or error, and EXPECTs a
PIPELINE_OK status before returning.

Also tweaked the naming of RunUntilIdle* to RunUntilQuit to avoid
confusion with the RunLoop::RunIntilIdle() API behaviour.

Bug: 836785
Change-Id: Idcf9bbec5ac0d7d78e2ba0530eaed0748a1626c8
Reviewed-on: https://chromium-review.googlesource.com/1041807Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555777}
parent e9e63bc7
...@@ -203,20 +203,17 @@ void PipelineIntegrationTestBase::OnEnded() { ...@@ -203,20 +203,17 @@ void PipelineIntegrationTestBase::OnEnded() {
} }
bool PipelineIntegrationTestBase::WaitUntilOnEnded() { bool PipelineIntegrationTestBase::WaitUntilOnEnded() {
if (!ended_) { EXPECT_EQ(pipeline_status_, PIPELINE_OK);
base::RunLoop run_loop; PipelineStatus status = WaitUntilEndedOrError();
RunUntilIdleOrEnded(&run_loop);
EXPECT_TRUE(ended_); EXPECT_TRUE(ended_);
} else { EXPECT_EQ(pipeline_status_, PIPELINE_OK);
scoped_task_environment_.RunUntilIdle(); return ended_ && (status == PIPELINE_OK);
}
return ended_ && (pipeline_status_ == PIPELINE_OK);
} }
PipelineStatus PipelineIntegrationTestBase::WaitUntilEndedOrError() { PipelineStatus PipelineIntegrationTestBase::WaitUntilEndedOrError() {
if (!ended_ && pipeline_status_ == PIPELINE_OK) { if (!ended_ && pipeline_status_ == PIPELINE_OK) {
base::RunLoop run_loop; base::RunLoop run_loop;
RunUntilIdleOrEndedOrError(&run_loop); RunUntilQuitOrEndedOrError(&run_loop);
} else { } else {
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
} }
...@@ -293,7 +290,7 @@ PipelineStatus PipelineIntegrationTestBase::StartInternal( ...@@ -293,7 +290,7 @@ PipelineStatus PipelineIntegrationTestBase::StartInternal(
this, this,
base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, base::Bind(&PipelineIntegrationTestBase::OnStatusCallback,
base::Unretained(this), run_loop.QuitWhenIdleClosure())); base::Unretained(this), run_loop.QuitWhenIdleClosure()));
RunUntilIdleOrEndedOrError(&run_loop); RunUntilQuitOrEndedOrError(&run_loop);
return pipeline_status_; return pipeline_status_;
} }
...@@ -361,7 +358,7 @@ bool PipelineIntegrationTestBase::Seek(base::TimeDelta seek_time) { ...@@ -361,7 +358,7 @@ bool PipelineIntegrationTestBase::Seek(base::TimeDelta seek_time) {
pipeline_->Seek(seek_time, base::Bind(&PipelineIntegrationTestBase::OnSeeked, pipeline_->Seek(seek_time, base::Bind(&PipelineIntegrationTestBase::OnSeeked,
base::Unretained(this), seek_time)); base::Unretained(this), seek_time));
RunUntilIdle(&run_loop); RunUntilQuit(&run_loop);
return (pipeline_status_ == PIPELINE_OK); return (pipeline_status_ == PIPELINE_OK);
} }
...@@ -370,7 +367,7 @@ bool PipelineIntegrationTestBase::Suspend() { ...@@ -370,7 +367,7 @@ bool PipelineIntegrationTestBase::Suspend() {
pipeline_->Suspend(base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, pipeline_->Suspend(base::Bind(&PipelineIntegrationTestBase::OnStatusCallback,
base::Unretained(this), base::Unretained(this),
run_loop.QuitWhenIdleClosure())); run_loop.QuitWhenIdleClosure()));
RunUntilIdle(&run_loop); RunUntilQuit(&run_loop);
return (pipeline_status_ == PIPELINE_OK); return (pipeline_status_ == PIPELINE_OK);
} }
...@@ -385,7 +382,7 @@ bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) { ...@@ -385,7 +382,7 @@ bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) {
seek_time, seek_time,
base::Bind(&PipelineIntegrationTestBase::OnSeeked, base::Bind(&PipelineIntegrationTestBase::OnSeeked,
base::Unretained(this), seek_time)); base::Unretained(this), seek_time));
RunUntilIdle(&run_loop); RunUntilQuit(&run_loop);
return (pipeline_status_ == PIPELINE_OK); return (pipeline_status_ == PIPELINE_OK);
} }
...@@ -431,7 +428,7 @@ bool PipelineIntegrationTestBase::WaitUntilCurrentTimeIsAfter( ...@@ -431,7 +428,7 @@ bool PipelineIntegrationTestBase::WaitUntilCurrentTimeIsAfter(
run_loop.QuitWhenIdleClosure()), run_loop.QuitWhenIdleClosure()),
base::TimeDelta::FromMilliseconds(10)); base::TimeDelta::FromMilliseconds(10));
RunUntilIdleOrEndedOrError(&run_loop); RunUntilQuitOrEndedOrError(&run_loop);
return (pipeline_status_ == PIPELINE_OK); return (pipeline_status_ == PIPELINE_OK);
} }
...@@ -649,7 +646,7 @@ PipelineStatus PipelineIntegrationTestBase::StartPipelineWithMediaSource( ...@@ -649,7 +646,7 @@ PipelineStatus PipelineIntegrationTestBase::StartPipelineWithMediaSource(
base::Unretained(encrypted_media))); base::Unretained(encrypted_media)));
} }
RunUntilIdleOrEndedOrError(&run_loop); RunUntilQuitOrEndedOrError(&run_loop);
for (auto* stream : demuxer_->GetAllStreams()) { for (auto* stream : demuxer_->GetAllStreams()) {
EXPECT_TRUE(stream->SupportsConfigChanges()); EXPECT_TRUE(stream->SupportsConfigChanges());
...@@ -658,35 +655,21 @@ PipelineStatus PipelineIntegrationTestBase::StartPipelineWithMediaSource( ...@@ -658,35 +655,21 @@ PipelineStatus PipelineIntegrationTestBase::StartPipelineWithMediaSource(
return pipeline_status_; return pipeline_status_;
} }
void PipelineIntegrationTestBase::RunUntilIdle(base::RunLoop* run_loop) { void PipelineIntegrationTestBase::RunUntilQuit(base::RunLoop* run_loop) {
RunUntilIdleEndedOrErrorInternal(run_loop, false, false); run_loop->Run();
} on_ended_closure_ = base::OnceClosure();
on_error_closure_ = base::OnceClosure();
void PipelineIntegrationTestBase::RunUntilIdleOrEnded(base::RunLoop* run_loop) { scoped_task_environment_.RunUntilIdle();
RunUntilIdleEndedOrErrorInternal(run_loop, true, false);
} }
void PipelineIntegrationTestBase::RunUntilIdleOrEndedOrError( void PipelineIntegrationTestBase::RunUntilQuitOrEndedOrError(
base::RunLoop* run_loop) { base::RunLoop* run_loop) {
RunUntilIdleEndedOrErrorInternal(run_loop, true, true);
}
void PipelineIntegrationTestBase::RunUntilIdleEndedOrErrorInternal(
base::RunLoop* run_loop,
bool run_until_ended,
bool run_until_error) {
DCHECK(on_ended_closure_.is_null()); DCHECK(on_ended_closure_.is_null());
DCHECK(on_error_closure_.is_null()); DCHECK(on_error_closure_.is_null());
if (run_until_ended)
on_ended_closure_ = run_loop->QuitWhenIdleClosure(); on_ended_closure_ = run_loop->QuitWhenIdleClosure();
if (run_until_error)
on_error_closure_ = run_loop->QuitWhenIdleClosure(); on_error_closure_ = run_loop->QuitWhenIdleClosure();
run_loop->Run(); RunUntilQuit(run_loop);
on_ended_closure_ = base::Closure();
on_error_closure_ = base::Closure();
scoped_task_environment_.RunUntilIdle();
} }
base::TimeTicks DummyTickClock::NowTicks() const { base::TimeTicks DummyTickClock::NowTicks() const {
......
...@@ -252,19 +252,16 @@ class PipelineIntegrationTestBase : public Pipeline::Client { ...@@ -252,19 +252,16 @@ class PipelineIntegrationTestBase : public Pipeline::Client {
MOCK_METHOD1(OnVideoDecoderChange, void(const std::string&)); MOCK_METHOD1(OnVideoDecoderChange, void(const std::string&));
private: private:
// Helpers that run |*run_loop|, where OnEnded() or OnError() are each // Runs |run_loop| until it is explicitly Quit() by some part of the calling
// conditionally setup to quit |*run_loop| when it becomes idle. Once // test fixture. The |scoped_task_environment_| is RunUntilIdle() after the
// |*run_loop|'s Run() Quits, these helpers also run // RunLoop finishes running, before returning to the caller.
// |scoped_task_environment_| until Idle. void RunUntilQuit(base::RunLoop* run_loop);
void RunUntilIdle(base::RunLoop* run_loop); // Configures |on_ended_closure_| and |on_error_closure_| to quit |run_loop|
void RunUntilIdleOrEnded(base::RunLoop* run_loop); // and then calls RunUntilQuit() on it.
void RunUntilIdleOrEndedOrError(base::RunLoop* run_loop); void RunUntilQuitOrEndedOrError(base::RunLoop* run_loop);
void RunUntilIdleEndedOrErrorInternal(base::RunLoop* run_loop,
bool run_until_ended, base::OnceClosure on_ended_closure_;
bool run_until_error); base::OnceClosure on_error_closure_;
base::Closure on_ended_closure_;
base::Closure on_error_closure_;
DISALLOW_COPY_AND_ASSIGN(PipelineIntegrationTestBase); DISALLOW_COPY_AND_ASSIGN(PipelineIntegrationTestBase);
}; };
......
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