forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mojo: do not dispatch SimpleWatcher callback twice upon ...FAILED_PRE…
…CONDITION We used to fire DataPipeDrainer::Client::OnDataComplete() twice because underlying SimpleWatcher fired its client callback twice when MOJO_RESULT_FAILED_PRECONDITION occurs after the remote end of data pipe is closed. Change-Id: I241aa6648dec79c2cf60e9c32de70a52d59d3412 Reviewed-on: https://chromium-review.googlesource.com/958094 Reviewed-by: Ken Rockot <rockot@chromium.org> Commit-Queue: Andrey Kosyakov <caseq@chromium.org> Cr-Commit-Position: refs/heads/master@{#542353}
- Loading branch information
Showing
5 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "mojo/common/data_pipe_drainer.h" | ||
#include "base/callback.h" | ||
#include "base/message_loop/message_loop.h" | ||
#include "base/run_loop.h" | ||
#include "base/values.h" | ||
#include "mojo/public/cpp/bindings/binding.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace mojo { | ||
namespace common { | ||
namespace test { | ||
|
||
template <typename Functor> | ||
base::RepeatingClosure BindLambda(Functor callable) { | ||
return base::BindRepeating([](Functor callable) { callable(); }, callable); | ||
} | ||
|
||
class DataPipeDrainerTest : public testing::Test, | ||
public DataPipeDrainer::Client { | ||
protected: | ||
DataPipeDrainerTest() { | ||
DataPipe pipe; | ||
drainer_ = std::make_unique<DataPipeDrainer>( | ||
this, std::move(pipe.consumer_handle)); | ||
producer_handle_ = std::move(pipe.producer_handle); | ||
} | ||
|
||
ScopedDataPipeProducerHandle producer_handle_; | ||
base::RepeatingClosure completion_callback_; | ||
|
||
void OnDataAvailable(const void* data, size_t num_bytes) override { | ||
data_.append(static_cast<const char*>(data), num_bytes); | ||
} | ||
|
||
void OnDataComplete() override { completion_callback_.Run(); } | ||
|
||
base::MessageLoop message_loop_; | ||
std::string data_; | ||
std::unique_ptr<DataPipeDrainer> drainer_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DataPipeDrainerTest); | ||
}; | ||
|
||
TEST_F(DataPipeDrainerTest, TestCompleteIsCalledOnce) { | ||
bool had_data_complete = false; | ||
|
||
completion_callback_ = BindLambda([&had_data_complete]() { | ||
EXPECT_FALSE(had_data_complete); | ||
had_data_complete = true; | ||
}); | ||
uint32_t size = 5; | ||
EXPECT_EQ(MOJO_RESULT_OK, producer_handle_->WriteData( | ||
"hello", &size, MOJO_WRITE_DATA_FLAG_NONE)); | ||
base::RunLoop().RunUntilIdle(); | ||
producer_handle_.reset(); | ||
base::RunLoop().RunUntilIdle(); | ||
} | ||
|
||
} // namespace test | ||
} // namespace common | ||
} // namespace mojo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters