Skip to content

Rewrite SimpleUnbufferedChannelTest in channel_test.cc #8160

Closed
@wangkuiyi

Description

@wangkuiyi

The follow unit test has the title SimpleUnbufferedChannelTest

TEST(Channel, SimpleUnbufferedChannelTest) {
auto ch = MakeChannel<int>(0);
unsigned sum_send = 0;
std::thread t([&]() {
for (int i = 0; i < 5; i++) {
EXPECT_EQ(ch->Send(&i), true);
sum_send += i;
}
});
for (int i = 0; i < 5; i++) {
int recv;
EXPECT_EQ(ch->Receive(&recv), true);
EXPECT_EQ(recv, i);
}
CloseChannel(ch);
t.join();
EXPECT_EQ(sum_send, 10U);
delete ch;
}

This implies that it is specifically design to test unbuffered channels.

However, the logic would pass with buffered channels too.

It seems that we should

  1. either rename it to SimpleChannelTest -- remove the word "Unbuffered", or
  2. rewrite it so that it works with unbuffered channel and fails with buffered channels.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions