Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Jan 3, 2024
1 parent d0d7bac commit 292d242
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions test/core/transport/promise_endpoint_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ TEST_F(PromiseEndpointTest, OneWriteSuccessful) {
activity.Activate();
EXPECT_CALL(activity, WakeupRequested).Times(0);
EXPECT_CALL(mock_endpoint_, Write).WillOnce(Return(true));
auto promise = promise_endpoint_->Write(
SliceBuffer(Slice::FromCopiedString("hello world")));
auto poll = promise();
ASSERT_TRUE(poll.ready());
EXPECT_EQ(absl::OkStatus(), poll.value());
activity.Deactivate();
}

TEST_F(PromiseEndpointTest, EmptyWriteIsNoOp) {
MockActivity activity;
activity.Activate();
EXPECT_CALL(activity, WakeupRequested).Times(0);
EXPECT_CALL(mock_endpoint_, Write).Times(0);
auto promise = promise_endpoint_->Write(SliceBuffer());
auto poll = promise();
ASSERT_TRUE(poll.ready());
Expand All @@ -541,7 +554,8 @@ TEST_F(PromiseEndpointTest, OneWriteFailed) {
on_write(this->kDummyErrorStatus);
return false;
}));
auto promise = promise_endpoint_->Write(SliceBuffer());
auto promise = promise_endpoint_->Write(
SliceBuffer(Slice::FromCopiedString("hello world")));
auto poll = promise();
ASSERT_TRUE(poll.ready());
EXPECT_EQ(kDummyErrorStatus, poll.value());
Expand All @@ -564,7 +578,8 @@ TEST_F(PromiseEndpointTest, OnePendingWriteSuccessful) {
// Return false to mock EventEngine write pending..
return false;
}));
auto promise = promise_endpoint_->Write(SliceBuffer());
auto promise = promise_endpoint_->Write(
SliceBuffer(Slice::FromCopiedString("hello world")));
EXPECT_TRUE(promise().pending());
// Mock EventEngine write succeeds, and promise resolves.
write_callback(absl::OkStatus());
Expand All @@ -586,7 +601,8 @@ TEST_F(PromiseEndpointTest, OnePendingWriteFailed) {
// Return false to mock EventEngine write pending..
return false;
}));
auto promise = promise_endpoint_->Write(SliceBuffer());
auto promise = promise_endpoint_->Write(
SliceBuffer(Slice::FromCopiedString("hello world")));
EXPECT_TRUE(promise().pending());
write_callback(kDummyErrorStatus);
auto poll = promise();
Expand Down Expand Up @@ -807,8 +823,10 @@ TEST_F(MultiplePromiseEndpointTest, JoinWritesSuccessful) {
EXPECT_CALL(on_done, Call(absl::OkStatus()));
auto activity = MakeActivity(
[this] {
return Seq(Join(this->first_promise_endpoint_.Write(SliceBuffer()),
this->second_promise_endpoint_.Write(SliceBuffer())),
return Seq(Join(this->first_promise_endpoint_.Write(SliceBuffer(
Slice::FromCopiedString("hello world"))),
this->second_promise_endpoint_.Write(SliceBuffer(
Slice::FromCopiedString("hello world")))),
[](std::tuple<absl::Status, absl::Status> ret) {
// Both writes finish with `absl::OkStatus`.
EXPECT_TRUE(std::get<0>(ret).ok());
Expand All @@ -832,8 +850,10 @@ TEST_F(MultiplePromiseEndpointTest, JoinOneWriteSuccessfulOneWriteFailed) {
EXPECT_CALL(on_done, Call(kDummyErrorStatus));
auto activity = MakeActivity(
[this] {
return Seq(Join(this->first_promise_endpoint_.Write(SliceBuffer()),
this->second_promise_endpoint_.Write(SliceBuffer())),
return Seq(Join(this->first_promise_endpoint_.Write(SliceBuffer(
Slice::FromCopiedString("hello world"))),
this->second_promise_endpoint_.Write(SliceBuffer(
Slice::FromCopiedString("hello world")))),
[this](std::tuple<absl::Status, absl::Status> ret) {
// One write finish with `absl::OkStatus` and the other
// write fails.
Expand Down Expand Up @@ -864,8 +884,10 @@ TEST_F(MultiplePromiseEndpointTest, JoinWritesFailed) {
EXPECT_CALL(on_done, Call(kDummyErrorStatus));
auto activity = MakeActivity(
[this] {
return Seq(Join(this->first_promise_endpoint_.Write(SliceBuffer()),
this->second_promise_endpoint_.Write(SliceBuffer())),
return Seq(Join(this->first_promise_endpoint_.Write(SliceBuffer(
Slice::FromCopiedString("hello world"))),
this->second_promise_endpoint_.Write(SliceBuffer(
Slice::FromCopiedString("hello world")))),
[this](std::tuple<absl::Status, absl::Status> ret) {
// Both writes fail with errors.
EXPECT_FALSE(std::get<0>(ret).ok());
Expand Down

0 comments on commit 292d242

Please sign in to comment.