diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 74d5e11..c5fa0a8 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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 diff --git a/tests/channel_test.cpp b/tests/channel_test.cpp index 5583957..1ddbcfa 100644 --- a/tests/channel_test.cpp +++ b/tests/channel_test.cpp @@ -49,6 +49,39 @@ TEST(ChannelTest, PushAndFetch) EXPECT_EQ(4, out); } +TEST(ChannelTest, PushAndFetchWithBufferedChannel) +{ + msd::channel 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 channel;