Skip to content

Test push and fetch with buffered channel #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ jobs:

- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --config Debug --target tests
run: cmake --build . --config Debug --target tests -j

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C Debug --verbose -R channel_test
run: ctest -C Debug --verbose -R channel_test -j

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
Expand Down
33 changes: 33 additions & 0 deletions tests/channel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@ TEST(ChannelTest, PushAndFetch)
EXPECT_EQ(4, out);
}

TEST(ChannelTest, PushAndFetchWithBufferedChannel)
{
msd::channel<int> channel{2};

auto push = [&channel]() {
channel << 1;
channel << 2;
channel << 3;
};

auto read = [&channel]() {
// Wait before reading to test the case where the channel is full and waiting
// for the reader to read some items.
std::this_thread::sleep_for(std::chrono::milliseconds(100));

int out = 0;

channel >> out;
EXPECT_EQ(1, out);

channel >> out;
EXPECT_EQ(2, out);

channel >> out;
EXPECT_EQ(3, out);
};

std::thread push_thread{push};
std::thread read_thread{read};
push_thread.join();
read_thread.join();
}

TEST(ChannelTest, PushAndFetchMultiple)
{
msd::channel<int> channel;
Expand Down